From 261442af210d652fc2c8a3d9197097982701bd16 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 19 Sep 2011 11:57:52 +0300 Subject: [PATCH] TUT framework updated to svn version Libs headers moved to its own folders --- stglibs/common.lib/{ => include/stg}/common.h | 0 .../{ => include/stg}/conffiles.h | 0 stglibs/crypto.lib/{ => include/stg}/ag_md5.h | 0 .../crypto.lib/{ => include/stg}/blowfish.h | 0 .../{ => include/stg}/dotconfpp.h | 0 stglibs/ia.lib/{ => include/stg}/ia.h | 0 stglibs/ibpp.lib/{ => include/stg}/ibpp.h | 0 stglibs/locker.lib/{ => include/stg}/locker.h | 0 stglibs/logger.lib/{ => include/stg}/logger.h | 0 stglibs/pinger.lib/{ => include/stg}/pinger.h | 0 .../{ => include/stg}/scriptexecuter.h | 0 stglibs/smux.lib/{ => include/stg}/ANY.h | 0 .../{ => include/stg}/ApplicationSyntax.h | 0 stglibs/smux.lib/{ => include/stg}/AtEntry.h | 0 .../smux.lib/{ => include/stg}/BIT_STRING.h | 0 stglibs/smux.lib/{ => include/stg}/BOOLEAN.h | 0 stglibs/smux.lib/{ => include/stg}/ClosePDU.h | 0 stglibs/smux.lib/{ => include/stg}/Counter.h | 0 .../{ => include/stg}/DisplayString.h | 0 .../{ => include/stg}/EgpNeighEntry.h | 0 stglibs/smux.lib/{ => include/stg}/Gauge.h | 0 .../{ => include/stg}/GetNextRequest-PDU.h | 0 .../{ => include/stg}/GetRequest-PDU.h | 0 .../{ => include/stg}/GetResponse-PDU.h | 0 stglibs/smux.lib/{ => include/stg}/INTEGER.h | 0 stglibs/smux.lib/{ => include/stg}/IfEntry.h | 0 .../smux.lib/{ => include/stg}/IpAddrEntry.h | 0 .../smux.lib/{ => include/stg}/IpAddress.h | 0 .../{ => include/stg}/IpNetToMediaEntry.h | 0 .../smux.lib/{ => include/stg}/IpRouteEntry.h | 0 stglibs/smux.lib/{ => include/stg}/Message.h | 0 stglibs/smux.lib/{ => include/stg}/NULL.h | 0 .../{ => include/stg}/NativeEnumerated.h | 0 .../{ => include/stg}/NativeInteger.h | 0 .../{ => include/stg}/NetworkAddress.h | 0 .../{ => include/stg}/OBJECT_IDENTIFIER.h | 0 .../smux.lib/{ => include/stg}/OCTET_STRING.h | 0 .../smux.lib/{ => include/stg}/ObjectName.h | 0 .../smux.lib/{ => include/stg}/ObjectSyntax.h | 0 stglibs/smux.lib/{ => include/stg}/Opaque.h | 0 stglibs/smux.lib/{ => include/stg}/OpenPDU.h | 0 stglibs/smux.lib/{ => include/stg}/PDU.h | 0 stglibs/smux.lib/{ => include/stg}/PDUs.h | 0 .../smux.lib/{ => include/stg}/PhysAddress.h | 0 stglibs/smux.lib/{ => include/stg}/RReqPDU.h | 0 stglibs/smux.lib/{ => include/stg}/RRspPDU.h | 0 .../smux.lib/{ => include/stg}/SMUX-PDUs.h | 0 stglibs/smux.lib/{ => include/stg}/SOutPDU.h | 0 .../{ => include/stg}/SetRequest-PDU.h | 0 .../smux.lib/{ => include/stg}/SimpleOpen.h | 0 .../smux.lib/{ => include/stg}/SimpleSyntax.h | 0 .../smux.lib/{ => include/stg}/TcpConnEntry.h | 0 .../smux.lib/{ => include/stg}/TimeTicks.h | 0 stglibs/smux.lib/{ => include/stg}/Trap-PDU.h | 0 stglibs/smux.lib/{ => include/stg}/UdpEntry.h | 0 stglibs/smux.lib/{ => include/stg}/VarBind.h | 0 .../smux.lib/{ => include/stg}/VarBindList.h | 0 .../{ => include/stg}/asn_SEQUENCE_OF.h | 0 .../smux.lib/{ => include/stg}/asn_SET_OF.h | 0 .../{ => include/stg}/asn_application.h | 0 .../smux.lib/{ => include/stg}/asn_codecs.h | 0 .../{ => include/stg}/asn_codecs_prim.h | 0 .../smux.lib/{ => include/stg}/asn_internal.h | 0 .../smux.lib/{ => include/stg}/asn_system.h | 0 .../smux.lib/{ => include/stg}/ber_decoder.h | 0 .../{ => include/stg}/ber_tlv_length.h | 0 .../smux.lib/{ => include/stg}/ber_tlv_tag.h | 0 .../{ => include/stg}/constr_CHOICE.h | 0 .../{ => include/stg}/constr_SEQUENCE.h | 0 .../{ => include/stg}/constr_SEQUENCE_OF.h | 0 .../{ => include/stg}/constr_SET_OF.h | 0 .../smux.lib/{ => include/stg}/constr_TYPE.h | 0 .../smux.lib/{ => include/stg}/constraints.h | 0 .../smux.lib/{ => include/stg}/der_encoder.h | 0 .../smux.lib/{ => include/stg}/per_decoder.h | 0 .../smux.lib/{ => include/stg}/per_encoder.h | 0 .../smux.lib/{ => include/stg}/per_support.h | 0 .../smux.lib/{ => include/stg}/xer_decoder.h | 0 .../smux.lib/{ => include/stg}/xer_encoder.h | 0 .../smux.lib/{ => include/stg}/xer_support.h | 0 .../srvconf.lib/{ => include/stg}/netunit.h | 0 .../srvconf.lib/{ => include/stg}/servconf.h | 0 tests/tut.h | 2 - tests/tut/tut.hpp | 136 +++++++---- tests/tut/tut_assert.hpp | 155 ++++++++++-- tests/tut/tut_config.hpp | 6 + tests/tut/tut_console_reporter.hpp | 95 +++++--- tests/tut/tut_cppunit_reporter.hpp | 213 +++++++++-------- tests/tut/tut_exception.hpp | 92 +++++++- tests/tut/tut_fpt.hpp | 185 +++++++++++++++ tests/tut/tut_macros.hpp | 63 +++++ tests/tut/tut_main.hpp | 111 +++++++++ tests/tut/tut_posix.hpp | 37 ++- tests/tut/tut_restartable.hpp | 9 +- tests/tut/tut_result.hpp | 79 +++++-- tests/tut/tut_runner.hpp | 55 +++-- tests/tut/tut_xml_reporter.hpp | 220 +++++++----------- tests/tut_reporter.h | 5 - tests/tut_restartable.h | 2 - 99 files changed, 1061 insertions(+), 404 deletions(-) rename stglibs/common.lib/{ => include/stg}/common.h (100%) rename stglibs/conffiles.lib/{ => include/stg}/conffiles.h (100%) rename stglibs/crypto.lib/{ => include/stg}/ag_md5.h (100%) rename stglibs/crypto.lib/{ => include/stg}/blowfish.h (100%) rename stglibs/dotconfpp.lib/{ => include/stg}/dotconfpp.h (100%) rename stglibs/ia.lib/{ => include/stg}/ia.h (100%) rename stglibs/ibpp.lib/{ => include/stg}/ibpp.h (100%) rename stglibs/locker.lib/{ => include/stg}/locker.h (100%) rename stglibs/logger.lib/{ => include/stg}/logger.h (100%) rename stglibs/pinger.lib/{ => include/stg}/pinger.h (100%) rename stglibs/scriptexecuter.lib/{ => include/stg}/scriptexecuter.h (100%) rename stglibs/smux.lib/{ => include/stg}/ANY.h (100%) rename stglibs/smux.lib/{ => include/stg}/ApplicationSyntax.h (100%) rename stglibs/smux.lib/{ => include/stg}/AtEntry.h (100%) rename stglibs/smux.lib/{ => include/stg}/BIT_STRING.h (100%) rename stglibs/smux.lib/{ => include/stg}/BOOLEAN.h (100%) rename stglibs/smux.lib/{ => include/stg}/ClosePDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/Counter.h (100%) rename stglibs/smux.lib/{ => include/stg}/DisplayString.h (100%) rename stglibs/smux.lib/{ => include/stg}/EgpNeighEntry.h (100%) rename stglibs/smux.lib/{ => include/stg}/Gauge.h (100%) rename stglibs/smux.lib/{ => include/stg}/GetNextRequest-PDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/GetRequest-PDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/GetResponse-PDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/INTEGER.h (100%) rename stglibs/smux.lib/{ => include/stg}/IfEntry.h (100%) rename stglibs/smux.lib/{ => include/stg}/IpAddrEntry.h (100%) rename stglibs/smux.lib/{ => include/stg}/IpAddress.h (100%) rename stglibs/smux.lib/{ => include/stg}/IpNetToMediaEntry.h (100%) rename stglibs/smux.lib/{ => include/stg}/IpRouteEntry.h (100%) rename stglibs/smux.lib/{ => include/stg}/Message.h (100%) rename stglibs/smux.lib/{ => include/stg}/NULL.h (100%) rename stglibs/smux.lib/{ => include/stg}/NativeEnumerated.h (100%) rename stglibs/smux.lib/{ => include/stg}/NativeInteger.h (100%) rename stglibs/smux.lib/{ => include/stg}/NetworkAddress.h (100%) rename stglibs/smux.lib/{ => include/stg}/OBJECT_IDENTIFIER.h (100%) rename stglibs/smux.lib/{ => include/stg}/OCTET_STRING.h (100%) rename stglibs/smux.lib/{ => include/stg}/ObjectName.h (100%) rename stglibs/smux.lib/{ => include/stg}/ObjectSyntax.h (100%) rename stglibs/smux.lib/{ => include/stg}/Opaque.h (100%) rename stglibs/smux.lib/{ => include/stg}/OpenPDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/PDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/PDUs.h (100%) rename stglibs/smux.lib/{ => include/stg}/PhysAddress.h (100%) rename stglibs/smux.lib/{ => include/stg}/RReqPDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/RRspPDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/SMUX-PDUs.h (100%) rename stglibs/smux.lib/{ => include/stg}/SOutPDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/SetRequest-PDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/SimpleOpen.h (100%) rename stglibs/smux.lib/{ => include/stg}/SimpleSyntax.h (100%) rename stglibs/smux.lib/{ => include/stg}/TcpConnEntry.h (100%) rename stglibs/smux.lib/{ => include/stg}/TimeTicks.h (100%) rename stglibs/smux.lib/{ => include/stg}/Trap-PDU.h (100%) rename stglibs/smux.lib/{ => include/stg}/UdpEntry.h (100%) rename stglibs/smux.lib/{ => include/stg}/VarBind.h (100%) rename stglibs/smux.lib/{ => include/stg}/VarBindList.h (100%) rename stglibs/smux.lib/{ => include/stg}/asn_SEQUENCE_OF.h (100%) rename stglibs/smux.lib/{ => include/stg}/asn_SET_OF.h (100%) rename stglibs/smux.lib/{ => include/stg}/asn_application.h (100%) rename stglibs/smux.lib/{ => include/stg}/asn_codecs.h (100%) rename stglibs/smux.lib/{ => include/stg}/asn_codecs_prim.h (100%) rename stglibs/smux.lib/{ => include/stg}/asn_internal.h (100%) rename stglibs/smux.lib/{ => include/stg}/asn_system.h (100%) rename stglibs/smux.lib/{ => include/stg}/ber_decoder.h (100%) rename stglibs/smux.lib/{ => include/stg}/ber_tlv_length.h (100%) rename stglibs/smux.lib/{ => include/stg}/ber_tlv_tag.h (100%) rename stglibs/smux.lib/{ => include/stg}/constr_CHOICE.h (100%) rename stglibs/smux.lib/{ => include/stg}/constr_SEQUENCE.h (100%) rename stglibs/smux.lib/{ => include/stg}/constr_SEQUENCE_OF.h (100%) rename stglibs/smux.lib/{ => include/stg}/constr_SET_OF.h (100%) rename stglibs/smux.lib/{ => include/stg}/constr_TYPE.h (100%) rename stglibs/smux.lib/{ => include/stg}/constraints.h (100%) rename stglibs/smux.lib/{ => include/stg}/der_encoder.h (100%) rename stglibs/smux.lib/{ => include/stg}/per_decoder.h (100%) rename stglibs/smux.lib/{ => include/stg}/per_encoder.h (100%) rename stglibs/smux.lib/{ => include/stg}/per_support.h (100%) rename stglibs/smux.lib/{ => include/stg}/xer_decoder.h (100%) rename stglibs/smux.lib/{ => include/stg}/xer_encoder.h (100%) rename stglibs/smux.lib/{ => include/stg}/xer_support.h (100%) rename stglibs/srvconf.lib/{ => include/stg}/netunit.h (100%) rename stglibs/srvconf.lib/{ => include/stg}/servconf.h (100%) delete mode 100644 tests/tut.h create mode 100644 tests/tut/tut_config.hpp create mode 100644 tests/tut/tut_fpt.hpp create mode 100644 tests/tut/tut_macros.hpp create mode 100644 tests/tut/tut_main.hpp delete mode 100644 tests/tut_reporter.h delete mode 100644 tests/tut_restartable.h diff --git a/stglibs/common.lib/common.h b/stglibs/common.lib/include/stg/common.h similarity index 100% rename from stglibs/common.lib/common.h rename to stglibs/common.lib/include/stg/common.h diff --git a/stglibs/conffiles.lib/conffiles.h b/stglibs/conffiles.lib/include/stg/conffiles.h similarity index 100% rename from stglibs/conffiles.lib/conffiles.h rename to stglibs/conffiles.lib/include/stg/conffiles.h diff --git a/stglibs/crypto.lib/ag_md5.h b/stglibs/crypto.lib/include/stg/ag_md5.h similarity index 100% rename from stglibs/crypto.lib/ag_md5.h rename to stglibs/crypto.lib/include/stg/ag_md5.h diff --git a/stglibs/crypto.lib/blowfish.h b/stglibs/crypto.lib/include/stg/blowfish.h similarity index 100% rename from stglibs/crypto.lib/blowfish.h rename to stglibs/crypto.lib/include/stg/blowfish.h diff --git a/stglibs/dotconfpp.lib/dotconfpp.h b/stglibs/dotconfpp.lib/include/stg/dotconfpp.h similarity index 100% rename from stglibs/dotconfpp.lib/dotconfpp.h rename to stglibs/dotconfpp.lib/include/stg/dotconfpp.h diff --git a/stglibs/ia.lib/ia.h b/stglibs/ia.lib/include/stg/ia.h similarity index 100% rename from stglibs/ia.lib/ia.h rename to stglibs/ia.lib/include/stg/ia.h diff --git a/stglibs/ibpp.lib/ibpp.h b/stglibs/ibpp.lib/include/stg/ibpp.h similarity index 100% rename from stglibs/ibpp.lib/ibpp.h rename to stglibs/ibpp.lib/include/stg/ibpp.h diff --git a/stglibs/locker.lib/locker.h b/stglibs/locker.lib/include/stg/locker.h similarity index 100% rename from stglibs/locker.lib/locker.h rename to stglibs/locker.lib/include/stg/locker.h diff --git a/stglibs/logger.lib/logger.h b/stglibs/logger.lib/include/stg/logger.h similarity index 100% rename from stglibs/logger.lib/logger.h rename to stglibs/logger.lib/include/stg/logger.h diff --git a/stglibs/pinger.lib/pinger.h b/stglibs/pinger.lib/include/stg/pinger.h similarity index 100% rename from stglibs/pinger.lib/pinger.h rename to stglibs/pinger.lib/include/stg/pinger.h diff --git a/stglibs/scriptexecuter.lib/scriptexecuter.h b/stglibs/scriptexecuter.lib/include/stg/scriptexecuter.h similarity index 100% rename from stglibs/scriptexecuter.lib/scriptexecuter.h rename to stglibs/scriptexecuter.lib/include/stg/scriptexecuter.h diff --git a/stglibs/smux.lib/ANY.h b/stglibs/smux.lib/include/stg/ANY.h similarity index 100% rename from stglibs/smux.lib/ANY.h rename to stglibs/smux.lib/include/stg/ANY.h diff --git a/stglibs/smux.lib/ApplicationSyntax.h b/stglibs/smux.lib/include/stg/ApplicationSyntax.h similarity index 100% rename from stglibs/smux.lib/ApplicationSyntax.h rename to stglibs/smux.lib/include/stg/ApplicationSyntax.h diff --git a/stglibs/smux.lib/AtEntry.h b/stglibs/smux.lib/include/stg/AtEntry.h similarity index 100% rename from stglibs/smux.lib/AtEntry.h rename to stglibs/smux.lib/include/stg/AtEntry.h diff --git a/stglibs/smux.lib/BIT_STRING.h b/stglibs/smux.lib/include/stg/BIT_STRING.h similarity index 100% rename from stglibs/smux.lib/BIT_STRING.h rename to stglibs/smux.lib/include/stg/BIT_STRING.h diff --git a/stglibs/smux.lib/BOOLEAN.h b/stglibs/smux.lib/include/stg/BOOLEAN.h similarity index 100% rename from stglibs/smux.lib/BOOLEAN.h rename to stglibs/smux.lib/include/stg/BOOLEAN.h diff --git a/stglibs/smux.lib/ClosePDU.h b/stglibs/smux.lib/include/stg/ClosePDU.h similarity index 100% rename from stglibs/smux.lib/ClosePDU.h rename to stglibs/smux.lib/include/stg/ClosePDU.h diff --git a/stglibs/smux.lib/Counter.h b/stglibs/smux.lib/include/stg/Counter.h similarity index 100% rename from stglibs/smux.lib/Counter.h rename to stglibs/smux.lib/include/stg/Counter.h diff --git a/stglibs/smux.lib/DisplayString.h b/stglibs/smux.lib/include/stg/DisplayString.h similarity index 100% rename from stglibs/smux.lib/DisplayString.h rename to stglibs/smux.lib/include/stg/DisplayString.h diff --git a/stglibs/smux.lib/EgpNeighEntry.h b/stglibs/smux.lib/include/stg/EgpNeighEntry.h similarity index 100% rename from stglibs/smux.lib/EgpNeighEntry.h rename to stglibs/smux.lib/include/stg/EgpNeighEntry.h diff --git a/stglibs/smux.lib/Gauge.h b/stglibs/smux.lib/include/stg/Gauge.h similarity index 100% rename from stglibs/smux.lib/Gauge.h rename to stglibs/smux.lib/include/stg/Gauge.h diff --git a/stglibs/smux.lib/GetNextRequest-PDU.h b/stglibs/smux.lib/include/stg/GetNextRequest-PDU.h similarity index 100% rename from stglibs/smux.lib/GetNextRequest-PDU.h rename to stglibs/smux.lib/include/stg/GetNextRequest-PDU.h diff --git a/stglibs/smux.lib/GetRequest-PDU.h b/stglibs/smux.lib/include/stg/GetRequest-PDU.h similarity index 100% rename from stglibs/smux.lib/GetRequest-PDU.h rename to stglibs/smux.lib/include/stg/GetRequest-PDU.h diff --git a/stglibs/smux.lib/GetResponse-PDU.h b/stglibs/smux.lib/include/stg/GetResponse-PDU.h similarity index 100% rename from stglibs/smux.lib/GetResponse-PDU.h rename to stglibs/smux.lib/include/stg/GetResponse-PDU.h diff --git a/stglibs/smux.lib/INTEGER.h b/stglibs/smux.lib/include/stg/INTEGER.h similarity index 100% rename from stglibs/smux.lib/INTEGER.h rename to stglibs/smux.lib/include/stg/INTEGER.h diff --git a/stglibs/smux.lib/IfEntry.h b/stglibs/smux.lib/include/stg/IfEntry.h similarity index 100% rename from stglibs/smux.lib/IfEntry.h rename to stglibs/smux.lib/include/stg/IfEntry.h diff --git a/stglibs/smux.lib/IpAddrEntry.h b/stglibs/smux.lib/include/stg/IpAddrEntry.h similarity index 100% rename from stglibs/smux.lib/IpAddrEntry.h rename to stglibs/smux.lib/include/stg/IpAddrEntry.h diff --git a/stglibs/smux.lib/IpAddress.h b/stglibs/smux.lib/include/stg/IpAddress.h similarity index 100% rename from stglibs/smux.lib/IpAddress.h rename to stglibs/smux.lib/include/stg/IpAddress.h diff --git a/stglibs/smux.lib/IpNetToMediaEntry.h b/stglibs/smux.lib/include/stg/IpNetToMediaEntry.h similarity index 100% rename from stglibs/smux.lib/IpNetToMediaEntry.h rename to stglibs/smux.lib/include/stg/IpNetToMediaEntry.h diff --git a/stglibs/smux.lib/IpRouteEntry.h b/stglibs/smux.lib/include/stg/IpRouteEntry.h similarity index 100% rename from stglibs/smux.lib/IpRouteEntry.h rename to stglibs/smux.lib/include/stg/IpRouteEntry.h diff --git a/stglibs/smux.lib/Message.h b/stglibs/smux.lib/include/stg/Message.h similarity index 100% rename from stglibs/smux.lib/Message.h rename to stglibs/smux.lib/include/stg/Message.h diff --git a/stglibs/smux.lib/NULL.h b/stglibs/smux.lib/include/stg/NULL.h similarity index 100% rename from stglibs/smux.lib/NULL.h rename to stglibs/smux.lib/include/stg/NULL.h diff --git a/stglibs/smux.lib/NativeEnumerated.h b/stglibs/smux.lib/include/stg/NativeEnumerated.h similarity index 100% rename from stglibs/smux.lib/NativeEnumerated.h rename to stglibs/smux.lib/include/stg/NativeEnumerated.h diff --git a/stglibs/smux.lib/NativeInteger.h b/stglibs/smux.lib/include/stg/NativeInteger.h similarity index 100% rename from stglibs/smux.lib/NativeInteger.h rename to stglibs/smux.lib/include/stg/NativeInteger.h diff --git a/stglibs/smux.lib/NetworkAddress.h b/stglibs/smux.lib/include/stg/NetworkAddress.h similarity index 100% rename from stglibs/smux.lib/NetworkAddress.h rename to stglibs/smux.lib/include/stg/NetworkAddress.h diff --git a/stglibs/smux.lib/OBJECT_IDENTIFIER.h b/stglibs/smux.lib/include/stg/OBJECT_IDENTIFIER.h similarity index 100% rename from stglibs/smux.lib/OBJECT_IDENTIFIER.h rename to stglibs/smux.lib/include/stg/OBJECT_IDENTIFIER.h diff --git a/stglibs/smux.lib/OCTET_STRING.h b/stglibs/smux.lib/include/stg/OCTET_STRING.h similarity index 100% rename from stglibs/smux.lib/OCTET_STRING.h rename to stglibs/smux.lib/include/stg/OCTET_STRING.h diff --git a/stglibs/smux.lib/ObjectName.h b/stglibs/smux.lib/include/stg/ObjectName.h similarity index 100% rename from stglibs/smux.lib/ObjectName.h rename to stglibs/smux.lib/include/stg/ObjectName.h diff --git a/stglibs/smux.lib/ObjectSyntax.h b/stglibs/smux.lib/include/stg/ObjectSyntax.h similarity index 100% rename from stglibs/smux.lib/ObjectSyntax.h rename to stglibs/smux.lib/include/stg/ObjectSyntax.h diff --git a/stglibs/smux.lib/Opaque.h b/stglibs/smux.lib/include/stg/Opaque.h similarity index 100% rename from stglibs/smux.lib/Opaque.h rename to stglibs/smux.lib/include/stg/Opaque.h diff --git a/stglibs/smux.lib/OpenPDU.h b/stglibs/smux.lib/include/stg/OpenPDU.h similarity index 100% rename from stglibs/smux.lib/OpenPDU.h rename to stglibs/smux.lib/include/stg/OpenPDU.h diff --git a/stglibs/smux.lib/PDU.h b/stglibs/smux.lib/include/stg/PDU.h similarity index 100% rename from stglibs/smux.lib/PDU.h rename to stglibs/smux.lib/include/stg/PDU.h diff --git a/stglibs/smux.lib/PDUs.h b/stglibs/smux.lib/include/stg/PDUs.h similarity index 100% rename from stglibs/smux.lib/PDUs.h rename to stglibs/smux.lib/include/stg/PDUs.h diff --git a/stglibs/smux.lib/PhysAddress.h b/stglibs/smux.lib/include/stg/PhysAddress.h similarity index 100% rename from stglibs/smux.lib/PhysAddress.h rename to stglibs/smux.lib/include/stg/PhysAddress.h diff --git a/stglibs/smux.lib/RReqPDU.h b/stglibs/smux.lib/include/stg/RReqPDU.h similarity index 100% rename from stglibs/smux.lib/RReqPDU.h rename to stglibs/smux.lib/include/stg/RReqPDU.h diff --git a/stglibs/smux.lib/RRspPDU.h b/stglibs/smux.lib/include/stg/RRspPDU.h similarity index 100% rename from stglibs/smux.lib/RRspPDU.h rename to stglibs/smux.lib/include/stg/RRspPDU.h diff --git a/stglibs/smux.lib/SMUX-PDUs.h b/stglibs/smux.lib/include/stg/SMUX-PDUs.h similarity index 100% rename from stglibs/smux.lib/SMUX-PDUs.h rename to stglibs/smux.lib/include/stg/SMUX-PDUs.h diff --git a/stglibs/smux.lib/SOutPDU.h b/stglibs/smux.lib/include/stg/SOutPDU.h similarity index 100% rename from stglibs/smux.lib/SOutPDU.h rename to stglibs/smux.lib/include/stg/SOutPDU.h diff --git a/stglibs/smux.lib/SetRequest-PDU.h b/stglibs/smux.lib/include/stg/SetRequest-PDU.h similarity index 100% rename from stglibs/smux.lib/SetRequest-PDU.h rename to stglibs/smux.lib/include/stg/SetRequest-PDU.h diff --git a/stglibs/smux.lib/SimpleOpen.h b/stglibs/smux.lib/include/stg/SimpleOpen.h similarity index 100% rename from stglibs/smux.lib/SimpleOpen.h rename to stglibs/smux.lib/include/stg/SimpleOpen.h diff --git a/stglibs/smux.lib/SimpleSyntax.h b/stglibs/smux.lib/include/stg/SimpleSyntax.h similarity index 100% rename from stglibs/smux.lib/SimpleSyntax.h rename to stglibs/smux.lib/include/stg/SimpleSyntax.h diff --git a/stglibs/smux.lib/TcpConnEntry.h b/stglibs/smux.lib/include/stg/TcpConnEntry.h similarity index 100% rename from stglibs/smux.lib/TcpConnEntry.h rename to stglibs/smux.lib/include/stg/TcpConnEntry.h diff --git a/stglibs/smux.lib/TimeTicks.h b/stglibs/smux.lib/include/stg/TimeTicks.h similarity index 100% rename from stglibs/smux.lib/TimeTicks.h rename to stglibs/smux.lib/include/stg/TimeTicks.h diff --git a/stglibs/smux.lib/Trap-PDU.h b/stglibs/smux.lib/include/stg/Trap-PDU.h similarity index 100% rename from stglibs/smux.lib/Trap-PDU.h rename to stglibs/smux.lib/include/stg/Trap-PDU.h diff --git a/stglibs/smux.lib/UdpEntry.h b/stglibs/smux.lib/include/stg/UdpEntry.h similarity index 100% rename from stglibs/smux.lib/UdpEntry.h rename to stglibs/smux.lib/include/stg/UdpEntry.h diff --git a/stglibs/smux.lib/VarBind.h b/stglibs/smux.lib/include/stg/VarBind.h similarity index 100% rename from stglibs/smux.lib/VarBind.h rename to stglibs/smux.lib/include/stg/VarBind.h diff --git a/stglibs/smux.lib/VarBindList.h b/stglibs/smux.lib/include/stg/VarBindList.h similarity index 100% rename from stglibs/smux.lib/VarBindList.h rename to stglibs/smux.lib/include/stg/VarBindList.h diff --git a/stglibs/smux.lib/asn_SEQUENCE_OF.h b/stglibs/smux.lib/include/stg/asn_SEQUENCE_OF.h similarity index 100% rename from stglibs/smux.lib/asn_SEQUENCE_OF.h rename to stglibs/smux.lib/include/stg/asn_SEQUENCE_OF.h diff --git a/stglibs/smux.lib/asn_SET_OF.h b/stglibs/smux.lib/include/stg/asn_SET_OF.h similarity index 100% rename from stglibs/smux.lib/asn_SET_OF.h rename to stglibs/smux.lib/include/stg/asn_SET_OF.h diff --git a/stglibs/smux.lib/asn_application.h b/stglibs/smux.lib/include/stg/asn_application.h similarity index 100% rename from stglibs/smux.lib/asn_application.h rename to stglibs/smux.lib/include/stg/asn_application.h diff --git a/stglibs/smux.lib/asn_codecs.h b/stglibs/smux.lib/include/stg/asn_codecs.h similarity index 100% rename from stglibs/smux.lib/asn_codecs.h rename to stglibs/smux.lib/include/stg/asn_codecs.h diff --git a/stglibs/smux.lib/asn_codecs_prim.h b/stglibs/smux.lib/include/stg/asn_codecs_prim.h similarity index 100% rename from stglibs/smux.lib/asn_codecs_prim.h rename to stglibs/smux.lib/include/stg/asn_codecs_prim.h diff --git a/stglibs/smux.lib/asn_internal.h b/stglibs/smux.lib/include/stg/asn_internal.h similarity index 100% rename from stglibs/smux.lib/asn_internal.h rename to stglibs/smux.lib/include/stg/asn_internal.h diff --git a/stglibs/smux.lib/asn_system.h b/stglibs/smux.lib/include/stg/asn_system.h similarity index 100% rename from stglibs/smux.lib/asn_system.h rename to stglibs/smux.lib/include/stg/asn_system.h diff --git a/stglibs/smux.lib/ber_decoder.h b/stglibs/smux.lib/include/stg/ber_decoder.h similarity index 100% rename from stglibs/smux.lib/ber_decoder.h rename to stglibs/smux.lib/include/stg/ber_decoder.h diff --git a/stglibs/smux.lib/ber_tlv_length.h b/stglibs/smux.lib/include/stg/ber_tlv_length.h similarity index 100% rename from stglibs/smux.lib/ber_tlv_length.h rename to stglibs/smux.lib/include/stg/ber_tlv_length.h diff --git a/stglibs/smux.lib/ber_tlv_tag.h b/stglibs/smux.lib/include/stg/ber_tlv_tag.h similarity index 100% rename from stglibs/smux.lib/ber_tlv_tag.h rename to stglibs/smux.lib/include/stg/ber_tlv_tag.h diff --git a/stglibs/smux.lib/constr_CHOICE.h b/stglibs/smux.lib/include/stg/constr_CHOICE.h similarity index 100% rename from stglibs/smux.lib/constr_CHOICE.h rename to stglibs/smux.lib/include/stg/constr_CHOICE.h diff --git a/stglibs/smux.lib/constr_SEQUENCE.h b/stglibs/smux.lib/include/stg/constr_SEQUENCE.h similarity index 100% rename from stglibs/smux.lib/constr_SEQUENCE.h rename to stglibs/smux.lib/include/stg/constr_SEQUENCE.h diff --git a/stglibs/smux.lib/constr_SEQUENCE_OF.h b/stglibs/smux.lib/include/stg/constr_SEQUENCE_OF.h similarity index 100% rename from stglibs/smux.lib/constr_SEQUENCE_OF.h rename to stglibs/smux.lib/include/stg/constr_SEQUENCE_OF.h diff --git a/stglibs/smux.lib/constr_SET_OF.h b/stglibs/smux.lib/include/stg/constr_SET_OF.h similarity index 100% rename from stglibs/smux.lib/constr_SET_OF.h rename to stglibs/smux.lib/include/stg/constr_SET_OF.h diff --git a/stglibs/smux.lib/constr_TYPE.h b/stglibs/smux.lib/include/stg/constr_TYPE.h similarity index 100% rename from stglibs/smux.lib/constr_TYPE.h rename to stglibs/smux.lib/include/stg/constr_TYPE.h diff --git a/stglibs/smux.lib/constraints.h b/stglibs/smux.lib/include/stg/constraints.h similarity index 100% rename from stglibs/smux.lib/constraints.h rename to stglibs/smux.lib/include/stg/constraints.h diff --git a/stglibs/smux.lib/der_encoder.h b/stglibs/smux.lib/include/stg/der_encoder.h similarity index 100% rename from stglibs/smux.lib/der_encoder.h rename to stglibs/smux.lib/include/stg/der_encoder.h diff --git a/stglibs/smux.lib/per_decoder.h b/stglibs/smux.lib/include/stg/per_decoder.h similarity index 100% rename from stglibs/smux.lib/per_decoder.h rename to stglibs/smux.lib/include/stg/per_decoder.h diff --git a/stglibs/smux.lib/per_encoder.h b/stglibs/smux.lib/include/stg/per_encoder.h similarity index 100% rename from stglibs/smux.lib/per_encoder.h rename to stglibs/smux.lib/include/stg/per_encoder.h diff --git a/stglibs/smux.lib/per_support.h b/stglibs/smux.lib/include/stg/per_support.h similarity index 100% rename from stglibs/smux.lib/per_support.h rename to stglibs/smux.lib/include/stg/per_support.h diff --git a/stglibs/smux.lib/xer_decoder.h b/stglibs/smux.lib/include/stg/xer_decoder.h similarity index 100% rename from stglibs/smux.lib/xer_decoder.h rename to stglibs/smux.lib/include/stg/xer_decoder.h diff --git a/stglibs/smux.lib/xer_encoder.h b/stglibs/smux.lib/include/stg/xer_encoder.h similarity index 100% rename from stglibs/smux.lib/xer_encoder.h rename to stglibs/smux.lib/include/stg/xer_encoder.h diff --git a/stglibs/smux.lib/xer_support.h b/stglibs/smux.lib/include/stg/xer_support.h similarity index 100% rename from stglibs/smux.lib/xer_support.h rename to stglibs/smux.lib/include/stg/xer_support.h diff --git a/stglibs/srvconf.lib/netunit.h b/stglibs/srvconf.lib/include/stg/netunit.h similarity index 100% rename from stglibs/srvconf.lib/netunit.h rename to stglibs/srvconf.lib/include/stg/netunit.h diff --git a/stglibs/srvconf.lib/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h similarity index 100% rename from stglibs/srvconf.lib/servconf.h rename to stglibs/srvconf.lib/include/stg/servconf.h diff --git a/tests/tut.h b/tests/tut.h deleted file mode 100644 index 22859cdd..00000000 --- a/tests/tut.h +++ /dev/null @@ -1,2 +0,0 @@ - -#include diff --git a/tests/tut/tut.hpp b/tests/tut/tut.hpp index 93233a6a..52f9643c 100644 --- a/tests/tut/tut.hpp +++ b/tests/tut/tut.hpp @@ -1,5 +1,6 @@ #ifndef TUT_H_GUARD #define TUT_H_GUARD +#include #include #include @@ -9,11 +10,6 @@ #include #include #include -#include - -#if defined(linux) -#define TUT_USE_POSIX -#endif #include "tut_exception.hpp" #include "tut_result.hpp" @@ -35,6 +31,9 @@ namespace tut { +template +class test_group; + /** * Test object. Contains data test run upon and default test method * implementation. Inherited from Data to allow tests to @@ -43,12 +42,29 @@ namespace tut template class test_object : public Data, public test_object_posix { + template + friend class test_group; + + void set_test_group(const char *group) + { + current_test_group_ = group; + } + + void set_test_id(int current_test_id) + { + current_test_id_ = current_test_id; + } + public: /** * Default constructor */ test_object() + : called_method_was_a_dummy_test_(false), + current_test_id_(0), + current_test_name_(), + current_test_group_() { } @@ -62,9 +78,9 @@ public: return current_test_name_; } - void set_test_id(int current_test_id) + const std::string& get_test_group() const { - current_test_id_ = current_test_id; + return current_test_group_; } int get_test_id() const @@ -86,13 +102,17 @@ public: * Used to detect usused test numbers and avoid unnecessary * test object creation which may be time-consuming depending * on operations described in Data::Data() and Data::~Data(). - * TODO: replace with throwing special exception from default test. */ bool called_method_was_a_dummy_test_; + virtual ~test_object() + { + } + private: int current_test_id_; std::string current_test_name_; + std::string current_test_group_; }; @@ -126,6 +146,9 @@ struct tests_registerer template class test_group : public group_base, public test_group_posix { + test_group(const test_group&); + void operator=(const test_group&); + const char* name_; typedef void (test_object::*testmethod)(); @@ -139,13 +162,15 @@ class test_group : public group_base, public test_group_posix tests tests_; tests_iterator current_test_; - enum seh_result - { - SEH_OK, - SEH_CTOR, - SEH_TEST, - SEH_DUMMY - }; + enum seh_result + { + SEH_OK, +#if defined(TUT_USE_SEH) + SEH_CTOR, + SEH_TEST, +#endif + SEH_DUMMY + }; /** * Exception-in-destructor-safe smart-pointer class. @@ -201,11 +226,16 @@ class test_group : public group_base, public test_group_posix { try { +#if defined(TUT_USE_SEH) if (delete_obj() == false) { throw warning("destructor of test object raised" " an SEH exception"); } +#else + bool d = delete_obj(); + assert(d && "delete failed with SEH disabled: runtime bug?"); +#endif } catch (const std::exception& ex) { @@ -268,7 +298,9 @@ public: * Creates and registers test group with specified name. */ test_group(const char* name) - : name_(name) + : name_(name), + tests_(), + current_test_() { // register itself runner.get().register_group(name_,this); @@ -281,7 +313,9 @@ public: * This constructor is used in self-test run only. */ test_group(const char* name, test_runner& another_runner) - : name_(name) + : name_(name), + tests_(), + current_test_() { // register itself another_runner.register_group(name_, this); @@ -367,22 +401,23 @@ public: try { switch (run_test_seh_(ti->second, obj, current_test_name, ti->first)) - { - case SEH_CTOR: - throw bad_ctor("seh"); - break; - - case SEH_TEST: - throw seh("seh"); - break; - - case SEH_DUMMY: - tr.result = test_result::dummy; - break; - - case SEH_OK: - // ok - break; + { +#if defined(TUT_USE_SEH) + case SEH_CTOR: + throw bad_ctor("seh"); + break; + + case SEH_TEST: + throw seh("seh"); + break; +#endif + case SEH_DUMMY: + tr.result = test_result::dummy; + break; + + case SEH_OK: + // ok + break; } } catch (const rethrown& ex) @@ -393,13 +428,13 @@ public: catch (const tut_error& ex) { tr.result = ex.result(); - tr.exception_typeid = typeid(ex).name(); + tr.exception_typeid = ex.type(); tr.message = ex.what(); } catch (const std::exception& ex) { tr.result = test_result::ex; - tr.exception_typeid = typeid(ex).name(); + tr.exception_typeid = type_name(ex); tr.message = ex.what(); } catch (...) @@ -433,12 +468,12 @@ public: __try { #endif - if (obj.get() == 0) - { - reset_holder_(obj); - } + if (obj.get() == 0) + { + reset_holder_(obj); + } - obj->called_method_was_a_dummy_test_ = false; + obj->called_method_was_a_dummy_test_ = false; #if defined(TUT_USE_SEH) @@ -446,6 +481,7 @@ public: { #endif obj.get()->set_test_id(current_test_id); + obj.get()->set_test_group(name_); (obj.get()->*tm)(); #if defined(TUT_USE_SEH) } @@ -456,20 +492,20 @@ public: } #endif - if (obj->called_method_was_a_dummy_test_) - { - // do not call obj.release(); reuse object - return SEH_DUMMY; - } + if (obj->called_method_was_a_dummy_test_) + { + // do not call obj.release(); reuse object + return SEH_DUMMY; + } - current_test_name = obj->get_test_name(); - obj.permit_throw(); - obj.release(); + current_test_name = obj->get_test_name(); + obj.permit_throw(); + obj.release(); #if defined(TUT_USE_SEH) } __except(handle_seh_(::GetExceptionCode())) { - return SEH_CTOR; + return SEH_CTOR; } #endif return SEH_OK; @@ -531,5 +567,5 @@ inline int handle_seh_(DWORD excode) #endif } -#endif +#endif // TUT_H_GUARD diff --git a/tests/tut/tut_assert.hpp b/tests/tut/tut_assert.hpp index 7ee44bc2..c1959012 100644 --- a/tests/tut/tut_assert.hpp +++ b/tests/tut/tut_assert.hpp @@ -1,29 +1,34 @@ #ifndef TUT_ASSERT_H_GUARD #define TUT_ASSERT_H_GUARD +#include -#include "tut_exception.hpp" #include #include +#include +#include +#include #if defined(TUT_USE_POSIX) #include #include #endif +#include "tut_exception.hpp" + namespace tut { namespace detail { template - std::ostream &msg_prefix(std::ostream &str, const M &msg) + std::ostringstream &msg_prefix(std::ostringstream &str, const M &msg) { - std::stringstream ss; + std::ostringstream ss; ss << msg; if(!ss.str().empty()) { - str << ss.rdbuf() << ": "; + str << msg << ": "; } return str; @@ -83,7 +88,7 @@ void ensure_not(const M& msg, bool cond) * Tests two objects for being equal. * Throws if false. * - * NB: both T and Q must have operator << defined somewhere, or + * NB: both LHS and RHS must have operator << defined somewhere, or * client code will not compile at all! */ template @@ -91,42 +96,128 @@ void ensure_equals(const M& msg, const LHS& actual, const RHS& expected) { if (expected != actual) { - std::stringstream ss; + std::ostringstream ss; detail::msg_prefix(ss,msg) - << "expected '" + << "expected `" << expected - << "' actual '" + << "` actual `" << actual - << '\''; + << "`"; throw failure(ss.str()); } } -template -void ensure_equals(const LHS& actual, const RHS& expected) +/** + * Tests two pointers for being equal. + * Throws if false. + * + * NB: both T and Q must have operator << defined somewhere, or + * client code will not compile at all! + */ +template +void ensure_equals(const M& msg, const LHS * const actual, const RHS * const expected) { - ensure_equals("Values are not equal", actual, expected); + if (expected != actual) + { + std::ostringstream ss; + detail::msg_prefix(ss,msg) + << "expected `" + << (void*)expected + << "` actual `" + << (void*)actual + << "`"; + throw failure(ss.str()); + } } template -void ensure_equals(const M& msg, const double& actual, const double& expected, - const double& epsilon = std::numeric_limits::epsilon()) +void ensure_equals(const M& msg, const double& actual, const double& expected, const double& epsilon) { const double diff = actual - expected; - if ( !((diff <= epsilon) && (diff >= -epsilon )) ) + if ( (actual != expected) && !((diff <= epsilon) && (diff >= -epsilon )) ) { - std::stringstream ss; + std::ostringstream ss; detail::msg_prefix(ss,msg) << std::scientific << std::showpoint << std::setprecision(16) - << "expected " << expected - << " actual " << actual - << " with precision " << epsilon; + << "expected `" << expected + << "` actual `" << actual + << "` with precision `" << epsilon << "`"; throw failure(ss.str()); } } + +template +void ensure_equals(const M& msg, const double& actual, const double& expected) +{ + ensure_equals(msg, actual, expected, std::numeric_limits::epsilon()); +} + +template +void ensure_equals(const LHS& actual, const RHS& expected) +{ + ensure_equals("Values are not equal", actual, expected); +} + + +template +void ensure_equals(const std::string &msg, + const LhsIterator &lhs_begin, const LhsIterator &lhs_end, + const RhsIterator &rhs_begin, const RhsIterator &rhs_end) +{ + typename std::iterator_traits::difference_type lhs_size = std::distance(lhs_begin, lhs_end); + typename std::iterator_traits::difference_type rhs_size = std::distance(rhs_begin, rhs_end); + + if(lhs_size < rhs_size) + { + ensure_equals(msg + ": range is too short", lhs_size, rhs_size); + } + + if(lhs_size > rhs_size) + { + ensure_equals(msg + ": range is too long", lhs_size, rhs_size); + } + + assert(lhs_size == rhs_size); + + LhsIterator lhs_i = lhs_begin; + RhsIterator rhs_i = rhs_begin; + while( (lhs_i != lhs_end) && (rhs_i != rhs_end) ) + { + if(*lhs_i != *rhs_i) + { + std::ostringstream ss; + detail::msg_prefix(ss,msg) + << "expected `" << *rhs_i + << "` actual `" << *lhs_i + << "` at offset " << std::distance(lhs_begin, lhs_i); + throw failure(ss.str()); + } + + lhs_i++; + rhs_i++; + } + + assert(lhs_i == lhs_end); + assert(rhs_i == rhs_end); +} + +template +void ensure_equals(const LhsIterator &lhs_begin, const LhsIterator &lhs_end, + const RhsIterator &rhs_begin, const RhsIterator &rhs_end) +{ + ensure_equals("Ranges are not equal", lhs_begin, lhs_end, rhs_begin, rhs_end); +} + +template +void ensure_equals(const LhsType *lhs_begin, const LhsType *lhs_end, + const RhsType *rhs_begin, const RhsType *rhs_end) +{ + ensure_equals("Ranges are not equal", lhs_begin, lhs_end, rhs_begin, rhs_end); +} + /** * Tests two objects for being at most in given distance one from another. * Borders are excluded. @@ -143,15 +234,15 @@ void ensure_distance(const M& msg, const T& actual, const T& expected, const T& { if (expected-distance >= actual || expected+distance <= actual) { - std::stringstream ss; + std::ostringstream ss; detail::msg_prefix(ss,msg) - << " expected (" + << " expected `" << expected-distance - << " - " + << "` - `" << expected+distance - << ") actual '" + << "` actual `" << actual - << '\''; + << "`"; throw failure(ss.str()); } } @@ -169,7 +260,7 @@ void ensure_errno(const M& msg, bool cond) { #if defined(TUT_USE_POSIX) char e[512]; - std::stringstream ss; + std::ostringstream ss; detail::msg_prefix(ss,msg) << strerror_r(errno, e, sizeof(e)); throw failure(ss.str()); @@ -193,6 +284,20 @@ void fail(const M& msg) throw failure(msg); } +/** + * Mark test case as known failure and skip execution. + */ +void skip(const char* msg = "") +{ + throw skipped(msg); +} + +template +void skip(const M& msg) +{ + throw skipped(msg); +} + } // end of namespace } diff --git a/tests/tut/tut_config.hpp b/tests/tut/tut_config.hpp new file mode 100644 index 00000000..d698c1c8 --- /dev/null +++ b/tests/tut/tut_config.hpp @@ -0,0 +1,6 @@ +#ifndef TUT_CONFIG_H_GUARD +#define TUT_CONFIG_H_GUARD + +#define TUT_USE_RTTI 1 + +#endif diff --git a/tests/tut/tut_console_reporter.hpp b/tests/tut/tut_console_reporter.hpp index 3c3739be..33856db8 100644 --- a/tests/tut/tut_console_reporter.hpp +++ b/tests/tut/tut_console_reporter.hpp @@ -1,6 +1,5 @@ #ifndef TUT_CONSOLE_REPORTER #define TUT_CONSOLE_REPORTER - #include #include @@ -17,29 +16,32 @@ std::ostream& operator<<(std::ostream& os, const tut::test_result& tr) { switch(tr.result) { - case tut::test_result::ok: - os << '.'; - break; - case tut::test_result::fail: - os << '[' << tr.test << "=F]"; - break; - case tut::test_result::ex_ctor: - os << '[' << tr.test << "=C]"; - break; - case tut::test_result::ex: - os << '[' << tr.test << "=X]"; - break; - case tut::test_result::warn: - os << '[' << tr.test << "=W]"; - break; - case tut::test_result::term: - os << '[' << tr.test << "=T]"; - break; - case tut::test_result::rethrown: - os << '[' << tr.test << "=P]"; - break; - case tut::test_result::dummy: - assert(!"Should never be called"); + case tut::test_result::ok: + os << '.'; + break; + case tut::test_result::fail: + os << '[' << tr.test << "=F]"; + break; + case tut::test_result::ex_ctor: + os << '[' << tr.test << "=C]"; + break; + case tut::test_result::ex: + os << '[' << tr.test << "=X]"; + break; + case tut::test_result::warn: + os << '[' << tr.test << "=W]"; + break; + case tut::test_result::term: + os << '[' << tr.test << "=T]"; + break; + case tut::test_result::rethrown: + os << '[' << tr.test << "=P]"; + break; + case tut::test_result::skipped: + os << '[' << tr.test << "=S]"; + break; + case tut::test_result::dummy: + throw tut::tut_error("console reporter called for dummy test result"); } return os; @@ -60,6 +62,8 @@ class console_reporter : public tut::callback not_passed_list not_passed; std::ostream& os; + console_reporter(const console_reporter &); + console_reporter &operator=(const console_reporter &); public: int ok_count; @@ -67,15 +71,33 @@ public: int failures_count; int terminations_count; int warnings_count; + int skipped_count; console_reporter() - : os(std::cout) + : current_group(), + not_passed(), + os(std::cout), + ok_count(0), + exceptions_count(0), + failures_count(0), + terminations_count(0), + warnings_count(0), + skipped_count(0) { init(); } console_reporter(std::ostream& out) - : os(out) + : current_group(), + not_passed(), + os(out), + ok_count(0), + exceptions_count(0), + failures_count(0), + terminations_count(0), + warnings_count(0), + skipped_count(0) + { init(); } @@ -114,11 +136,15 @@ public: case test_result::term: terminations_count++; break; + case test_result::skipped: + skipped_count++; + break; case tut::test_result::dummy: - assert(!"Should never be called"); + assert( (tr.result != tut::test_result::dummy) && "Should never be called"); } // switch - if (tr.result != tut::test_result::ok) + if ( (tr.result != tut::test_result::ok) && + (tr.result != tut::test_result::skipped) ) { not_passed.push_back(tr); } @@ -181,12 +207,12 @@ public: { if (tr.result == test_result::fail) { - os << " failed assertion: \"" << tr.message << "\"" + os << " failed assertion: `" << tr.message << "`" << std::endl; } else { - os << " message: \"" << tr.message << "\"" + os << " message: `" << tr.message << "`" << std::endl; } } @@ -214,11 +240,17 @@ public: { os << " warnings:" << warnings_count; } + os << " ok:" << ok_count; + + if(skipped_count > 0) + { + os << " skipped:" << skipped_count; + } os << std::endl; } - bool all_ok() const + virtual bool all_ok() const { return not_passed.empty(); } @@ -232,6 +264,7 @@ private: failures_count = 0; terminations_count = 0; warnings_count = 0; + skipped_count = 0; not_passed.clear(); } }; diff --git a/tests/tut/tut_cppunit_reporter.hpp b/tests/tut/tut_cppunit_reporter.hpp index 3b9f38c1..62646b09 100644 --- a/tests/tut/tut_cppunit_reporter.hpp +++ b/tests/tut/tut_cppunit_reporter.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace tut { @@ -16,72 +17,60 @@ namespace tut */ class cppunit_reporter : public tut::callback { - private: - std::vector failed_tests; - std::vector passed_tests; - std::string filename; + std::vector failed_tests_; + std::vector passed_tests_; + const std::string filename_; + std::auto_ptr stream_; - std::string encode(const std::string & text) - { - std::string out; - for (unsigned int i=0; i': - out += ">"; - break; - case '&': - out += "&"; - break; - case '\'': - out += "'"; - break; - case '"': - out += """; - break; - default: - out += c; - } - } - - return out; - } + cppunit_reporter(const cppunit_reporter &); + cppunit_reporter &operator=(const cppunit_reporter &); public: + explicit cppunit_reporter(const std::string &filename = "testResult.xml") + : failed_tests_(), + passed_tests_(), + filename_(filename), + stream_(new std::ofstream(filename_.c_str())) + { + if (!stream_->good()) { + throw tut_error("Cannot open output file `" + filename_ + "`"); + } + } - cppunit_reporter(const std::string & _filename = "") + explicit cppunit_reporter(std::ostream &stream) + : failed_tests_(), + passed_tests_(), + filename_(), + stream_(&stream) { - setFilename(_filename); } - void setFilename(const std::string & _filename) + ~cppunit_reporter() { - if (_filename == "") - { - filename = "testResult.xml"; - } - else + if(filename_.empty()) { - filename = _filename; + stream_.release(); } } void run_started() { - failed_tests.clear(); - passed_tests.clear(); + failed_tests_.clear(); + passed_tests_.clear(); } void test_completed(const tut::test_result& tr) { - if (tr.result == test_result::ok) { - passed_tests.push_back(tr); - } else { - failed_tests.push_back(tr); + assert(tr.result != test_result::dummy ); + if ( (tr.result == test_result::ok) || + (tr.result == test_result::skipped) ) + { + passed_tests_.push_back(tr); + } + else + { + failed_tests_.push_back(tr); } } @@ -91,23 +80,18 @@ public: int failures = 0; std::string failure_type; std::string failure_msg; - std::ofstream xmlfile; - - xmlfile.open(filename.c_str(), std::ios::in | std::ios::trunc); - if (!xmlfile.is_open()) { - throw (std::runtime_error("Cannot open file for output")); - } - /* *********************** header ***************************** */ - xmlfile << "" << std::endl - << "" << std::endl; + *stream_ << "" << std::endl + << "" << std::endl; - /* *********************** failed tests ***************************** */ - if (failed_tests.size() > 0) { - xmlfile << " " << std::endl; + if (failed_tests_.size() > 0) + { + *stream_ << " " << std::endl; - for (unsigned int i=0; i" << std::endl - << " " << encode(failed_tests[i].group) + "::" + encode(failed_tests[i].name) << "" << std::endl - << " " << failure_type << "" << std::endl - << " " << std::endl - << " Unknown" << std::endl - << " Unknown" << std::endl - << " " << std::endl - << " " << encode(failure_msg + failed_tests[i].message) << "" << std::endl - << " " << std::endl; + *stream_ << " " << std::endl + << " " << encode(failed_tests_[i].group) + "::" + encode(failed_tests_[i].name) << "" << std::endl + << " " << failure_type << "" << std::endl + << " " << std::endl + << " Unknown" << std::endl + << " Unknown" << std::endl + << " " << std::endl + << " " << encode(failure_msg + failed_tests_[i].message) << "" << std::endl + << " " << std::endl; } - xmlfile << " " << std::endl; + *stream_ << " " << std::endl; } /* *********************** passed tests ***************************** */ - if (passed_tests.size() > 0) { - xmlfile << " " << std::endl; - - for (unsigned int i=0; i" << std::endl - << " " << encode(passed_tests[i].group) + "::" + encode(passed_tests[i].name) << "" << std::endl - << " " << std::endl; + if (passed_tests_.size() > 0) { + *stream_ << " " << std::endl; + + for (unsigned int i=0; i" << std::endl + << " " << encode(passed_tests_[i].group) + "::" + encode(passed_tests_[i].name) << "" << std::endl + << " " << std::endl; } - xmlfile << " " << std::endl; + *stream_ << " " << std::endl; } /* *********************** statistics ***************************** */ - xmlfile << " " << std::endl - << " " << (failed_tests.size() + passed_tests.size()) << "" << std::endl - << " " << failed_tests.size() << "" << std::endl - << " " << errors << "" << std::endl - << " " << failures << "" << std::endl - << " " << std::endl; + *stream_ << " " << std::endl + << " " << (failed_tests_.size() + passed_tests_.size()) << "" << std::endl + << " " << failed_tests_.size() << "" << std::endl + << " " << errors << "" << std::endl + << " " << failures << "" << std::endl + << " " << std::endl; /* *********************** footer ***************************** */ - xmlfile << "" << std::endl; - - xmlfile.close(); + *stream_ << "" << std::endl; } - bool all_ok() const + virtual bool all_ok() const { - return failed_tests.empty(); - }; + return failed_tests_.empty(); + } + /** + * \brief Encodes text to XML + * XML-reserved characters (e.g. "<") are encoded according to specification + * @param text text to be encoded + * @return encoded string + */ + static std::string encode(const std::string & text) + { + std::string out; + + for (unsigned int i=0; i': + out += ">"; + break; + case '&': + out += "&"; + break; + case '\'': + out += "'"; + break; + case '"': + out += """; + break; + default: + out += c; + } + } + return out; + } }; } diff --git a/tests/tut/tut_exception.hpp b/tests/tut/tut_exception.hpp index c5c88cb2..1ebea341 100644 --- a/tests/tut/tut_exception.hpp +++ b/tests/tut/tut_exception.hpp @@ -12,7 +12,7 @@ namespace tut */ struct tut_error : public std::exception { - tut_error(const std::string& msg) + explicit tut_error(const std::string& msg) : err_msg(msg) { } @@ -22,6 +22,11 @@ struct tut_error : public std::exception return test_result::ex; } + virtual std::string type() const + { + return "tut::tut_error"; + } + const char* what() const throw() { return err_msg.c_str(); @@ -32,8 +37,9 @@ struct tut_error : public std::exception } private: + void operator=(const tut_error &); - std::string err_msg; + const std::string err_msg; }; /** @@ -41,23 +47,48 @@ private: */ struct no_such_group : public tut_error { - no_such_group(const std::string& grp) + explicit no_such_group(const std::string& grp) : tut_error(grp) { } + virtual std::string type() const + { + return "tut::no_such_group"; + } + ~no_such_group() throw() { } }; +/** + * Test not found exception. + */ +struct no_such_test : public tut_error +{ + explicit no_such_test(const std::string& grp) + : tut_error(grp) + { + } + + virtual std::string type() const + { + return "tut::no_such_test"; + } + + ~no_such_test() throw() + { + } +}; + /** * Internal exception to be throwed when * test constructor has failed. */ struct bad_ctor : public tut_error { - bad_ctor(const std::string& msg) + explicit bad_ctor(const std::string& msg) : tut_error(msg) { } @@ -67,6 +98,11 @@ struct bad_ctor : public tut_error return test_result::ex_ctor; } + virtual std::string type() const + { + return "tut::bad_ctor"; + } + ~bad_ctor() throw() { } @@ -77,7 +113,7 @@ struct bad_ctor : public tut_error */ struct failure : public tut_error { - failure(const std::string& msg) + explicit failure(const std::string& msg) : tut_error(msg) { } @@ -87,6 +123,11 @@ struct failure : public tut_error return test_result::fail; } + virtual std::string type() const + { + return "tut::failure"; + } + ~failure() throw() { } @@ -97,7 +138,7 @@ struct failure : public tut_error */ struct warning : public tut_error { - warning(const std::string& msg) + explicit warning(const std::string& msg) : tut_error(msg) { } @@ -107,6 +148,11 @@ struct warning : public tut_error return test_result::warn; } + virtual std::string type() const + { + return "tut::warning"; + } + ~warning() throw() { } @@ -117,7 +163,7 @@ struct warning : public tut_error */ struct seh : public tut_error { - seh(const std::string& msg) + explicit seh(const std::string& msg) : tut_error(msg) { } @@ -127,6 +173,11 @@ struct seh : public tut_error return test_result::term; } + virtual std::string type() const + { + return "tut::seh"; + } + ~seh() throw() { } @@ -147,6 +198,11 @@ struct rethrown : public failure return test_result::rethrown; } + virtual std::string type() const + { + return "tut::rethrown"; + } + ~rethrown() throw() { } @@ -154,6 +210,28 @@ struct rethrown : public failure const test_result tr; }; +struct skipped : public tut_error +{ + explicit skipped(const std::string& msg) + : tut_error(msg) + { + } + + virtual test_result::result_type result() const + { + return test_result::skipped; + } + + virtual std::string type() const + { + return "tut::skipped"; + } + + ~skipped() throw() + { + } +}; + } #endif diff --git a/tests/tut/tut_fpt.hpp b/tests/tut/tut_fpt.hpp new file mode 100644 index 00000000..e8df8b06 --- /dev/null +++ b/tests/tut/tut_fpt.hpp @@ -0,0 +1,185 @@ +/** + * @brief Additional ensures for scientific/engineering applications. + * @author Joerg + * @date 07/04/2008 + */ +#ifndef TUT_Float_H_GUARD +#define TUT_Float_H_GUARD + +#include +#include + +namespace tut +{ + namespace detail + { + template + struct If + { + typedef Else type; + }; + + template + struct If + { + typedef Then type; + }; + + template + struct fpt_traits + { + struct StdNumericLimitsNotAvailable {}; + static const StdNumericLimitsNotAvailable static_check[ std::numeric_limits::is_specialized ]; + + static const T zero; + + typedef typename If::is_integer, + double, + T>::type Result; + + static T abs(const T &arg) + { + if(arg < zero) + return zero - arg; + else + return arg; + } + + static T sig(const T &arg) + { + if(arg < zero) + return -1; + else + return 1; + } + + static inline Result div(const Result &number, const T &divisor) + { + static_cast(static_check); + + if(number == zero && divisor == zero) + return std::numeric_limits::quiet_NaN(); + + if(number == zero) + return zero; + + if(divisor == zero) + return sig(number) * std::numeric_limits::infinity(); + + assert(zero < number); + assert(zero < divisor); + + // Avoid underflow + if(static_cast(1) < abs(divisor)) + { + // number / divisor < min <=> number < min * divisor + if( abs(number) < abs(divisor) * std::numeric_limits::min()) + { + return sig(divisor) * sig(number) * std::numeric_limits::min(); + } + } + + // Avoid overflow + if( abs(divisor) < static_cast(1)) + { + // number / divisor > max <=> number > max * divisor + if( abs(divisor) * std::numeric_limits::max() < abs(number)) + { + return sig(divisor) * sig(number) * std::numeric_limits::max(); + } + } + + return number / divisor; + } + }; + + template + const typename fpt_traits::StdNumericLimitsNotAvailable + fpt_traits::static_check[ std::numeric_limits::is_specialized ] = { {} }; + + template + const T fpt_traits::zero = static_cast(0); + + template + bool check_tolerance(T actual, T expected, U fraction) + { + typename fpt_traits::Result diff = fpt_traits::div( fpt_traits::abs( expected - actual ), + fpt_traits::abs( expected ) ); + + return (diff == fraction) || (diff < fraction); + } + + } // namespace detail + + template + void ensure_close(const char* msg, const T& actual, const T& expected, const U& tolerance ) + { + typedef detail::fpt_traits Traits; + + typename Traits::Result fraction = Traits::div( Traits::abs(static_cast(tolerance)), + static_cast(100) ); + if( !detail::check_tolerance(actual, expected, fraction) ) + { + std::ostringstream ss; + ss << ( msg ? msg : "" ) + << ( msg ? ": " : "" ) + << "expected `" + << expected + << "` and actual `" + << actual + << "` differ more than " + << tolerance + << "%"; + throw failure( ss.str().c_str() ); + } + } + + template + void ensure_close(const T& actual, const T& expected, const Tolerance& tolerance ) + { + ensure_close( 0, actual, expected, tolerance ); + } + + template + void ensure_close_fraction(const char* msg, const T& actual, const T& expected, const U& fraction) + { + typedef char StdNumericLimitsNotAvailable; + const StdNumericLimitsNotAvailable static_check[ std::numeric_limits::is_specialized ] = { 0 }; + static_cast(static_check); + + typedef typename detail::If::is_integer, + double, + U>::type Tolerance; + + if( !detail::check_tolerance(actual, expected, fraction) ) + { + std::ostringstream ss; + ss << ( msg ? msg : "" ) + << ( msg ? ": " : "" ) + << "expected `" + << expected + << "` and actual `" + << actual + << "` differ more than fraction `" + << fraction + << "`"; + throw failure( ss.str().c_str() ); + } + } + + template + void ensure_close_fraction( const char* msg, const T& actual, const T& expected, const int& tolerance ) + { + ensure_close(msg, actual, expected, double(tolerance)); + } + + template< typename T, typename Tolerance> + void ensure_close_fraction(const T& actual, const T& expected, const Tolerance& fraction) + { + ensure_close_fraction( 0, actual, expected, fraction ); + } + +} // namespace tut + +#endif + diff --git a/tests/tut/tut_macros.hpp b/tests/tut/tut_macros.hpp new file mode 100644 index 00000000..ed517d66 --- /dev/null +++ b/tests/tut/tut_macros.hpp @@ -0,0 +1,63 @@ +#ifndef TUT_MACROS_HPP +#define TUT_MACROS_HPP + +#include + +#ifdef ensure_THROW +#error ensure_THROW macro is already defined +#endif + +/** Helper macros to ensure that a call throws exception. + * \code + * #include + * ensure_THROW( this_function_should_throw_bad_alloc(), std::bad_alloc ); + * \endcode + */ +#define ensure_THROW( x, e ) \ +try \ +{ \ + x; \ + fail(#x " has not thrown expected exception " #e); \ +} \ +catch(const e &) \ +{ \ +} \ +catch(const std::exception &ex) \ +{ \ + fail( std::string(#x " has thrown unexpected exception ")+tut::type_name(ex)+": "+ex.what()); \ +} \ +catch(...) \ +{ \ + fail(#x " has thrown unexpected unknown exception"); \ +} + +#ifdef ensure_NO_THROW +#error ensure_NO_THROW macro is already defined +#endif + +/** Helper macro to ensure a call does not throw any exceptions. + * \code + * #include + * ensure_NO_THROW( this_function_should_never_throw() ); + * \endcode + */ +#define ensure_NO_THROW( x ) \ +try \ +{ \ + x; \ +} \ +catch(const std::exception &ex) \ +{ \ + fail( std::string(#x " has thrown unexpected exception ")+tut::type_name(ex)+": "+ex.what()); \ +} \ +catch(...) \ +{ \ + fail(#x " has thrown unexpected unknown exception"); \ +} + +#ifdef __COUNTER__ +#define TUT_TESTCASE(object) template<> template<> void object::test<__COUNTER__>() +#endif + +#endif + diff --git a/tests/tut/tut_main.hpp b/tests/tut/tut_main.hpp new file mode 100644 index 00000000..c6955bb2 --- /dev/null +++ b/tests/tut/tut_main.hpp @@ -0,0 +1,111 @@ +#ifndef TUT_MAIN_H +#define TUT_MAIN_H + +#include +#include +#include +#include +#include + +namespace tut +{ + +/** Helper function to make test binaries simpler. + * + * Example of basic usage follows. + * + * @code + * namespace tut { test_runner_singleton runner; } + * + * int main(int argc, char **argv) + * { + * if( tut_main(argc, argv) ) + * return 0; + * else + * return -1; + * } + * @endcode + * + * It is also possible to do some generic initialization before + * running any tests and cleanup before exiting application. + * Note that tut_main can throw tut::no_such_group or tut::no_such_test. + * + * @code + * namespace tut { test_runner_singleton runner; } + * + * int main(int argc, char **argv) + * { + * tut::xml_reporter reporter; + * tut::runner.get().insert_callback(&reporter); + * + * MyInit(); + * try + * { + * tut_main(argc, argv); + * } + * catch(const tut::tut_error &ex) + * { + * std::cerr << "TUT error: " << ex.what() << std::endl; + * } + * MyCleanup(); + * } + * @endcode + */ +inline bool tut_main(int argc, const char * const * const argv, std::ostream &os = std::cerr) +{ + std::stringstream usage; + usage << "Usage: " << argv[0] << " [group] [testcase]" << std::endl; + groupnames gr = runner.get().list_groups(); + usage << "Available test groups:" << std::endl; + for(groupnames::const_iterator i = gr.begin(); i != gr.end(); ++i) + { + usage << " " << *i << std::endl; + } + + if(argc>1) + { + if(std::string(argv[1]) == "-h" || + std::string(argv[1]) == "--help" || + std::string(argv[1]) == "/?" || + argc > 3) + { + os << usage.rdbuf(); + return false; + } + } + + // Check command line options. + switch(argc) + { + case 1: + runner.get().run_tests(); + break; + + case 2: + runner.get().run_tests(argv[1]); + break; + + case 3: + { + char *end; + int t = strtol(argv[2], &end, 10); + if(end != argv[2] + strlen(argv[2])) + { + throw no_such_test("`" + std::string(argv[2]) + "` should be a number"); + } + + test_result tr; + if(!runner.get().run_test(argv[1], t, tr) || tr.result == test_result::dummy) + { + throw no_such_test("No testcase `" + std::string(argv[2]) + "` in group `" + argv[1] + "`"); + } + } + break; + } + + return true; +} // tut_main() + +} + +#endif diff --git a/tests/tut/tut_posix.hpp b/tests/tut/tut_posix.hpp index 89a71305..c7cfe57a 100644 --- a/tests/tut/tut_posix.hpp +++ b/tests/tut/tut_posix.hpp @@ -1,5 +1,6 @@ #ifndef TUT_FORK_H_GUARD #define TUT_FORK_H_GUARD +#include #if defined(TUT_USE_POSIX) #include @@ -44,7 +45,7 @@ private: if(tr.result != test_result::ok) { - std::stringstream ss; + std::ostringstream ss; ss << int(tr.result) << "\n" << tr.group << "\n" << tr.test << "\n" @@ -57,6 +58,10 @@ private: ensure_errno("write() failed", w == size); } } + + virtual ~test_group_posix() + { + } }; template @@ -126,7 +131,8 @@ public: * Default constructor */ test_object_posix() - : pipe_(-1) + : pids_(), + pipe_(-1) { } @@ -142,7 +148,7 @@ public: if(!pids_.empty()) { - std::stringstream ss; + std::ostringstream ss; // in parent, reap children for(std::map::iterator i = pids_.begin(); i != pids_.end(); ++i) @@ -226,7 +232,7 @@ private: else { // cannot kill, we are in trouble - std::stringstream ss; + std::ostringstream ss; char e[1024]; ss << "child " << pid << " could not be killed with SIGTERM, " << strerror_r(errno, e, sizeof(e)) << std::endl; fail(ss.str()); @@ -257,7 +263,7 @@ private: } else { - std::stringstream ss; + std::ostringstream ss; char e[1024]; ss << "child " << pid << " could not be killed with SIGKILL, " << strerror_r(errno, e, sizeof(e)) << std::endl; fail(ss.str()); @@ -269,7 +275,7 @@ private: ensure_equals("child process exists after SIGKILL", ::kill(pid, 0), -1); - std::stringstream ss; + std::ostringstream ss; ss << "child " << pid << " had to be killed with SIGKILL"; fail(ss.str()); } @@ -361,7 +367,7 @@ private: { if(WIFSIGNALED(status)) { - std::stringstream ss; + std::ostringstream ss; ss << "child killed by signal " << WTERMSIG(status) << ": expected exit with code " << exit_status; @@ -372,7 +378,7 @@ private: { if(WEXITSTATUS(status) != exit_status) { - std::stringstream ss; + std::ostringstream ss; ss << "child exited, expected '" << exit_status << "' actual '" @@ -385,7 +391,7 @@ private: if(WIFSTOPPED(status)) { - std::stringstream ss; + std::ostringstream ss; ss << "child stopped by signal " << WTERMSIG(status) << ": expected exit with code " << exit_status; throw failure(ss.str().c_str()); @@ -398,7 +404,7 @@ private: { if(WTERMSIG(status) != signal) { - std::stringstream ss; + std::ostringstream ss; ss << "child killed by signal, expected '" << signal << "' actual '" @@ -410,7 +416,7 @@ private: if(WIFEXITED(status)) { - std::stringstream ss; + std::ostringstream ss; ss << "child exited with code " << WEXITSTATUS(status) << ": expected signal " << signal; @@ -419,7 +425,7 @@ private: if(WIFSTOPPED(status)) { - std::stringstream ss; + std::ostringstream ss; ss << "child stopped by signal " << WTERMSIG(status) << ": expected kill by signal " << signal; @@ -453,6 +459,9 @@ namespace tut struct test_object_posix { + virtual ~test_object_posix() + { + } }; struct test_group_posix @@ -461,6 +470,10 @@ struct test_group_posix void send_result_(const T*, const test_result &) { } + + virtual ~test_group_posix() + { + } }; } // namespace tut diff --git a/tests/tut/tut_restartable.hpp b/tests/tut/tut_restartable.hpp index eb6eb00e..9f929234 100644 --- a/tests/tut/tut_restartable.hpp +++ b/tests/tut/tut_restartable.hpp @@ -186,7 +186,7 @@ bool deserialize(std::istream& is, tut::test_result& tr) } return true; } -}; +} /** * Restartable test runner wrapper. @@ -207,11 +207,12 @@ public: */ restartable_wrapper(const std::string& dir = ".") : runner_(runner.get()), - dir_(dir) + callbacks_(), + dir_(dir), + log_( dir + '/' + "log.tut" ), + jrn_( dir + '/' + "journal.tut" ) { // dozen: it works, but it would be better to use system path separator - jrn_ = dir_ + '/' + "journal.tut"; - log_ = dir_ + '/' + "log.tut"; } /** diff --git a/tests/tut/tut_result.hpp b/tests/tut/tut_result.hpp index 5731802c..e9607859 100644 --- a/tests/tut/tut_result.hpp +++ b/tests/tut/tut_result.hpp @@ -1,11 +1,42 @@ #ifndef TUT_RESULT_H_GUARD #define TUT_RESULT_H_GUARD +#include #include +#if defined(TUT_USE_RTTI) +#if (defined(_MSC_VER) && !defined(_CPPRTTI)) || (defined(__GNUC__) && !defined(__GXX_RTTI)) +#undef TUT_USE_RTTI +#endif +#endif + +#if defined(TUT_USE_RTTI) +#include +#endif + namespace tut { +#if defined(TUT_USE_RTTI) +template +inline std::string type_name(const T& t) +{ + return typeid(t).name(); +} +#else +template +inline std::string type_name(const T& t) +{ + return "Unknown type, RTTI disabled"; +} + +inline std::string type_name(const std::exception&) +{ + return "Unknown std::exception, RTTI disabled"; +} +#endif + + #if defined(TUT_USE_POSIX) struct test_result_posix { @@ -14,11 +45,18 @@ struct test_result_posix { } + virtual ~test_result_posix() + { + } + pid_t pid; }; #else struct test_result_posix { + virtual ~test_result_posix() + { + } }; #endif @@ -46,22 +84,19 @@ struct test_result : public test_result_posix std::string name; /** - * ok - test finished successfully - * fail - test failed with ensure() or fail() methods - * ex - test throwed an exceptions - * warn - test finished successfully, but test destructor throwed - * term - test forced test application to terminate abnormally + * result of a test */ enum result_type { - ok, - fail, - ex, - warn, - term, - ex_ctor, - rethrown, - dummy + ok, ///< test finished successfully + fail, ///< test failed with ensure() or fail() methods + ex, ///< test throwed an exceptions + warn, ///< test finished successfully, but test destructor throwed + term, ///< test forced test application to terminate abnormally + ex_ctor, ///< + rethrown, ///< + skipped, ///< + dummy ///< }; result_type result; @@ -76,8 +111,12 @@ struct test_result : public test_result_posix * Default constructor. */ test_result() - : test(0), - result(ok) + : group(), + test(0), + name(), + result(ok), + message(), + exception_typeid() { } @@ -89,7 +128,9 @@ struct test_result : public test_result_posix : group(grp), test(pos), name(test_name), - result(res) + result(res), + message(), + exception_typeid() { } @@ -104,7 +145,7 @@ struct test_result : public test_result_posix name(test_name), result(res), message(ex.what()), - exception_typeid(typeid(ex).name()) + exception_typeid(type_name(ex)) { } @@ -122,6 +163,10 @@ struct test_result : public test_result_posix exception_typeid(ex_typeid) { } + + virtual ~test_result() + { + } }; } diff --git a/tests/tut/tut_runner.hpp b/tests/tut/tut_runner.hpp index 33ffe423..3803046e 100644 --- a/tests/tut/tut_runner.hpp +++ b/tests/tut/tut_runner.hpp @@ -62,24 +62,27 @@ struct callback * Called when a group started * @param name Name of the group */ - virtual void group_started(const std::string& /*name*/) + virtual void group_started(const std::string& name) { + (void)name; } /** * Called when a test finished. * @param tr Test results. */ - virtual void test_completed(const test_result& /*tr*/) + virtual void test_completed(const test_result& tr) { + (void)tr; } /** * Called when a group is completed * @param name Name of the group */ - virtual void group_completed(const std::string& /*name*/) + virtual void group_completed(const std::string& name) { + (void)name; } /** @@ -88,6 +91,11 @@ struct callback virtual void run_completed() { } + + virtual bool all_ok() const + { + return true; + } private: callback(const callback &); void operator=(const callback&); @@ -111,11 +119,15 @@ public: * Constructor */ test_runner() + : groups_(), + callbacks_() { } /** * Stores another group for getting by name. + * @param name new group object + * @param gr new callback object */ void register_group(const std::string& name, group_base* gr) { @@ -127,15 +139,16 @@ public: if (groups_.find(name) != groups_.end()) { std::string msg("attempt to add already existent group " + name); - // this exception terminates application so we use cerr also - // TODO: should this message appear in stream? - std::cerr << msg << std::endl; throw tut_error(msg); } groups_.insert( std::make_pair(name, gr) ); } + /** + * Stores one callback object. + * @param cb new callback object + */ void set_callback(callback *cb) { clear_callbacks(); @@ -143,7 +156,8 @@ public: } /** - * Stores callback object. + * Add callback object. + * @param cb new callback object */ void insert_callback(callback* cb) { @@ -153,11 +167,18 @@ public: } } + /** + * Remove callback object. + * @param cb callback to remove + */ void erase_callback(callback* cb) { callbacks_.erase(cb); } + /** + * Remove all callback objects. + */ void clear_callbacks() { callbacks_.clear(); @@ -165,12 +186,17 @@ public: /** * Returns callback list. + * @return callback list */ const callbacks &get_callbacks() const { return callbacks_; } + /** + * Set callback list. + * @param cb new callback list + */ void set_callbacks(const callbacks &cb) { callbacks_ = cb; @@ -178,23 +204,20 @@ public: /** * Returns list of known test groups. + * @return groups list */ const groupnames list_groups() const { groupnames ret; - const_iterator i = groups_.begin(); - const_iterator e = groups_.end(); - while (i != e) + for(const_iterator i = groups_.begin(); i != groups_.end(); ++i) { ret.push_back(i->first); - ++i; } return ret; } /** * Runs all tests in all groups. - * @param callback Callback object if exists; null otherwise */ void run_tests() const { @@ -216,6 +239,7 @@ public: /** * Runs all tests in specified group. + * @param group_name group to test */ void run_tests(const std::string& group_name) const { @@ -236,6 +260,10 @@ public: /** * Runs one test in specified group. + * @param group_name group to test + * @param n run case in test + * @param tr result of this case + * @return true if test is ok, otherwise false */ bool run_test(const std::string& group_name, int n, test_result &tr) const { @@ -356,4 +384,5 @@ extern test_runner_singleton runner; } -#endif +#endif // TUT_RUNNER_H_GUARD + diff --git a/tests/tut/tut_xml_reporter.hpp b/tests/tut/tut_xml_reporter.hpp index 8a9d5dec..d0c301dd 100644 --- a/tests/tut/tut_xml_reporter.hpp +++ b/tests/tut/tut_xml_reporter.hpp @@ -1,16 +1,9 @@ -/* - * tut_xml_reporter.hpp - * - * ECOS Library. IPT CS R&D CET ECOS Copyright 2008 Nokia - * Siemens Networks. All right - * - * - */ - #ifndef TUT_XML_REPORTER #define TUT_XML_REPORTER - +#include #include +#include +#include #include #include #include @@ -26,62 +19,12 @@ namespace tut */ class xml_reporter : public tut::callback { -protected: typedef std::vector TestResults; typedef std::map TestGroups; - TestGroups all_tests; /// holds all test results - std::string filename; /// filename base - - /** - * \brief Initializes object - * Resets counters and clears all stored test results. - */ - virtual void init() - { - ok_count = 0; - exceptions_count = 0; - failures_count = 0; - terminations_count = 0; - warnings_count = 0; - all_tests.clear(); - } - - /** - * \brief Encodes text to XML - * XML-reserved characters (e.g. "<") are encoded according to specification - * @param text text to be encoded - * @return encoded string - */ - virtual std::string encode(const std::string & text) - { - std::string out; - - for (unsigned int i=0; i': - out += ">"; - break; - case '&': - out += "&"; - break; - case '\'': - out += "'"; - break; - case '"': - out += """; - break; - default: - out += c; - } - } - - return out; - } + TestGroups all_tests_; /// holds all test results + const std::string filename_; /// filename base + std::auto_ptr stream_; /** * \brief Builds "testcase" XML entity with given parameters @@ -91,7 +34,7 @@ protected: * @param failure_msg failure message to be reported (empty, if test passed) * @return string with \ entity */ - virtual std::string xml_build_testcase(const tut::test_result & tr, const std::string & failure_type, + std::string xml_build_testcase(const tut::test_result & tr, const std::string & failure_type, const std::string & failure_msg, int pid = 0) { using std::endl; @@ -99,17 +42,18 @@ protected: std::ostringstream out; - if (tr.result == test_result::ok) + if ( (tr.result == test_result::ok) || + (tr.result == test_result::skipped) ) { - out << " "; + out << " "; } else { - string err_msg = encode(failure_msg + tr.message); + string err_msg = cppunit_reporter::encode(failure_msg + tr.message); string tag; // determines tag name: "failure" or "error" if ( tr.result == test_result::fail || tr.result == test_result::warn || - tr.result == test_result::ex || tr.result == test_result::ex_ctor ) + tr.result == test_result::ex || tr.result == test_result::ex_ctor || tr.result == test_result::rethrown ) { tag = "failure"; } @@ -118,16 +62,18 @@ protected: tag = "error"; } - out << " " << endl; - out << " <" << tag << " message=\"" << err_msg << "\"" << " type=\"" << failure_type << "\""; + out << " " << endl; + out << " <" << tag << " message=\"" << err_msg << "\"" << " type=\"" << failure_type << "\""; #if defined(TUT_USE_POSIX) if(pid != getpid()) { out << " child=\"" << pid << "\""; } +#else + (void)pid; #endif out << ">" << err_msg << "" << endl; - out << " "; + out << " "; } return out.str(); @@ -140,17 +86,17 @@ protected: * @param failures number of failures to be reported * @param total total number of tests to be reported * @param name test suite name - * @param testcases encoded XML string containing testcases + * @param testcases cppunit_reporter::encoded XML string containing testcases * @return string with \ entity */ - virtual std::string xml_build_testsuite(int errors, int failures, int total, + std::string xml_build_testsuite(int errors, int failures, int total, const std::string & name, const std::string & testcases) { std::ostringstream out; - out << "" << std::endl; + out << " " << std::endl; out << testcases; - out << ""; + out << " "; return out.str(); } @@ -165,39 +111,39 @@ public: /** * \brief Default constructor * @param filename base filename - * @see setFilenameBase */ - xml_reporter(const std::string & _filename = "") + xml_reporter(const std::string & filename) + : all_tests_(), + filename_(filename), + stream_(new std::ofstream(filename_.c_str())), + ok_count(0), + exceptions_count(0), + failures_count(0), + terminations_count(0), + warnings_count(0) { - init(); - setFilenameBase(_filename); + if (!stream_->good()) { + throw tut_error("Cannot open output file `" + filename_ + "`"); + } } - /** - * \brief Sets filename base for output - * @param _filename filename base - * Example usage: - * @code - * xml_reporter reporter; - * reporter.setFilenameBase("my_xml"); - * @endcode - * The above code will instruct reporter to create my_xml_1.xml file for the first test group, - * my_xml_2.xml file for the second, and so on. - */ - virtual void setFilenameBase(const std::string & _filename) + xml_reporter(std::ostream & stream) + : all_tests_(), + filename_(), + stream_(&stream), + ok_count(0), + exceptions_count(0), + failures_count(0), + terminations_count(0), + warnings_count(0) { - if (_filename == "") - { - filename = "testResult"; - } - else - { - if (_filename.length() > 200) - { - throw(std::runtime_error("Filename too long!")); - } + } - filename = _filename; + ~xml_reporter() + { + if(filename_.empty()) + { + stream_.release(); } } @@ -207,7 +153,12 @@ public: */ virtual void run_started() { - init(); + ok_count = 0; + exceptions_count = 0; + failures_count = 0; + terminations_count = 0; + warnings_count = 0; + all_tests_.clear(); } /** @@ -219,6 +170,7 @@ public: // update global statistics switch (tr.result) { case test_result::ok: + case test_result::skipped: ok_count++; break; case test_result::fail: @@ -235,60 +187,52 @@ public: case test_result::term: terminations_count++; break; + case tut::test_result::dummy: + assert(!"Should never be called"); } // switch // add test result to results table - (all_tests[tr.group]).push_back(tr); + all_tests_[tr.group].push_back(tr); } /** * \brief Callback function * This function is called when all tests are completed. It generates XML output - * to file(s). File name base can be set with \ref setFilenameBase. + * to file(s). File name base can be set with constructor. */ virtual void run_completed() { - using std::endl; - using std::string; - - static int number = 1; // results file sequence number (testResult_.xml) + /* *********************** header ***************************** */ + *stream_ << "" << std::endl; + *stream_ << "" << std::endl; // iterate over all test groups - TestGroups::const_iterator tgi; - for (tgi = all_tests.begin(); tgi != all_tests.end(); ++tgi) { + for (TestGroups::const_iterator tgi = all_tests_.begin(); tgi != all_tests_.end(); ++tgi) + { /* per-group statistics */ int passed = 0; // passed in single group int exceptions = 0; // exceptions in single group int failures = 0; // failures in single group int terminations = 0; // terminations in single group int warnings = 0; // warnings in single group - int errors = 0; // errors in single group + int errors = 0; // errors in single group - /* generate output filename */ - char fn[256]; - sprintf(fn, "%s_%d.xml", filename.c_str(), number++); - - std::ofstream xmlfile; - xmlfile.open(fn, std::ios::in | std::ios::trunc); - if (!xmlfile.is_open()) { - throw (std::runtime_error("Cannot open file for output")); - } - - /* *********************** header ***************************** */ - xmlfile << "" << endl; // output is written to string stream buffer, because JUnit format tag // contains statistics, which aren't known yet std::ostringstream out; // iterate over all test cases in the current test group - TestResults::const_iterator tri; - for (tri = (*tgi).second.begin(); tri != (*tgi).second.end(); ++tri) { - string failure_type; // string describing the failure type - string failure_msg; // a string with failure message + const TestResults &results = tgi->second; + for (TestResults::const_iterator tri = results.begin(); tri != results.end(); ++tri) + { + std::string failure_type; // string describing the failure type + std::string failure_msg; // a string with failure message - switch ((*tri).result) { + switch (tri->result) + { case test_result::ok: + case test_result::skipped: passed++; break; case test_result::fail: @@ -298,7 +242,7 @@ public: break; case test_result::ex: failure_type = "Assertion"; - failure_msg = "Thrown exception: " + (*tri).exception_typeid + '\n'; + failure_msg = "Thrown exception: " + tri->exception_typeid + '\n'; exceptions++; break; case test_result::warn: @@ -313,28 +257,27 @@ public: break; case test_result::ex_ctor: failure_type = "Assertion"; - failure_msg = "Constructor has thrown an exception: " + (*tri).exception_typeid + '\n'; + failure_msg = "Constructor has thrown an exception: " + tri->exception_typeid + ".\n"; exceptions++; break; case test_result::rethrown: failure_type = "Assertion"; - failure_msg = "Child failed"; + failure_msg = "Child failed.\n"; failures++; break; default: failure_type = "Error"; failure_msg = "Unknown test status, this should have never happened. " - "You may just have found a BUG in TUT XML reporter, please report it immediately.\n"; + "You may just have found a bug in TUT, please report it immediately.\n"; errors++; break; } // switch #if defined(TUT_USE_POSIX) - out << xml_build_testcase(*tri, failure_type, failure_msg, (*tri).pid) << endl; + out << xml_build_testcase(*tri, failure_type, failure_msg, tri->pid) << std::endl; #else - out << xml_build_testcase(*tri, failure_type, failure_msg) << endl; + out << xml_build_testcase(*tri, failure_type, failure_msg) << std::endl; #endif - } // iterate over all test cases // calculate per-group statistics @@ -342,9 +285,10 @@ public: int stat_failures = failures + warnings + exceptions; int stat_all = stat_errors + stat_failures + passed; - xmlfile << xml_build_testsuite(stat_errors, stat_failures, stat_all, (*tgi).first/* name */, out.str()/* testcases */) << endl; - xmlfile.close(); + *stream_ << xml_build_testsuite(stat_errors, stat_failures, stat_all, (*tgi).first/* name */, out.str()/* testcases */) << std::endl; } // iterate over all test groups + + *stream_ << "" << std::endl; } /** diff --git a/tests/tut_reporter.h b/tests/tut_reporter.h deleted file mode 100644 index e568635a..00000000 --- a/tests/tut_reporter.h +++ /dev/null @@ -1,5 +0,0 @@ - -#include -#include -#include -#include diff --git a/tests/tut_restartable.h b/tests/tut_restartable.h deleted file mode 100644 index c7897797..00000000 --- a/tests/tut_restartable.h +++ /dev/null @@ -1,2 +0,0 @@ - -#include -- 2.43.2