<commit_before>// 
//
// Copyright (C) 2010 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2010 SIPez LLC  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
// Author: <NAME>
//         dpetrie AT SIPez DOT com
//////////////////////////////////////////////////////////////////////////////

#ifndef _SipxPortUnitTestClass_h_
#define _SipxPortUnitTestClass_h_

// SYSTEM INCLUDES

// APPLICATION INCLUDES
#include <SipxPortUnitTestEnvironment.h>

// DEFINES

// MACROS
#define CPPUNIT_TEST_SUB_SUITE(CHILD_CLASS_NAME, PARENT_CLASS_NAME) \
    CPPUNIT_TEST_SUITE(CHILD_CLASS_NAME)

#define CPPUNIT_TEST_SUITE(CLASS_NAME) \
    public: \
    /* Not implemented here so actual tests can code constructor 
       and destructors
    CLASS_NAME() : \
        SipxPortUnitTestClass(#CLASS_NAME) \
    { \
    } \
 \
    ~  CLASS_NAME() \
    { \
        char buffer[256]; \
        sprintf(buffer, "Entering ~%s\n", \
                #CLASS_NAME); \
        SipxPortUnitTestEnvironment::printOut(buffer); \
         \
    } */\
 \
    static int getMethodCount() \
    { \
        initializeStatics(); \
        return(sMethodCount); \
    } \
    virtual const char* getCurrentMethodName() const\
    { \
        assert(spMethodNames); \
        return(mCurrentMethodIndex >= 0 && \
               mCurrentMethodIndex < sMethodCount ? \
               spMethodNames[mCurrentMethodIndex] : \
               0); \
    } \
 \
    virtual void incrementTestPointsPassed() \
    { \
        sTestPointsPassed++; \
        SipxPortUnitTestEnvironment::incrementTestPointsPassed(); \
    } \
 \
    static int getPassedTestPointCount() \
    { \
        return(sTestPointsPassed); \
    } \
 \
    static int getFailedTestPointCount() \
    { \
        return(sTestPointsFailed); \
    } \
 \
    virtual void incrementTestPointsFailed() \
    { \
        sTestPointsFailed++; \
        SipxPortUnitTestEnvironment::incrementTestPointsFailed(); \
    } \
 \
    static int getFailureCount() \
    { \
        return(sTestPointFailureCount); \
    } \
 \
    static SipxPortUnitTestPointFailure* getFailure(int failureIndex) \
    { \
        assert(failureIndex >= 0); \
        assert(failureIndex < SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS); \
        return(sTestPointFailures[failureIndex]); \
    } \
 \
    static bool addFailure(SipxPortUnitTestPointFailure* failure) \
    { \
        bool wasAdded = false; \
        if(sTestPointFailureCount < SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS) \
        { \
            sTestPointFailures[sTestPointFailureCount] = failure; \
            sTestPointFailureCount++; \
            wasAdded = true; \
        } \
        else \
        { \
            char message[SIPX_PORT_UNIT_MAX_ERROR_MESSAGE_SIZE]; \
            sprintf(message, "WARNING: maximum failures of %d excedded for class: %s, failure not added: %s\n", \
                    SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS, \
                    failure->getClassName(), failure->getMessage()); \
            SipxPortUnitTestEnvironment::printOut(message); \
        } \
        return(wasAdded); \
    } \
 \
    private: \
    static int sInitialized; \
    static int sInitializedSignature; \
    static int sMethodCount; \
    static char** spMethodNames; \
    static SipxPortTestMethodState* spMethodStates; \
    static int sTestPointsPassed; \
    static int sTestPointsFailed; \
    static int sTestPointFailureCount; \
    static SipxPortUnitTestPointFailure* sTestPointFailures[SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS]; \
 \
    void runAllMethodsFrom(int startMethodIndex) \
    { \
        forEachTestMethod(RUN_ALL_FROM, this, startMethodIndex); \
    } \
 \
    void addFailedTestPoint(const char* fileName, \
                            const char* className, \
                            const char* methodName, \
                            int testPoint, \
                            int lineNumber, \
                            const char* message) \
    { \
        SipxPortUnitTestPointFailure* failure = \
            new SipxPortUnitTestPointFailure(fileName, \
                                             className, \
                                             methodName, \
                                             testPoint, \
                                             lineNumber, \
                                             message); \
        if(!addFailure(failure)) \
        { \
            /* not added. array is full, so clean up */ \
            delete failure; \
            failure = 0; \
        } \
    } \
 \
    static void initializeStatics() \
    { \
        if(!sInitialized || \
           sInitializedSignature != SIPX_PORT_UNIT_TEST_SIGNATURE) \
        { \
            sInitialized == false; \
            sMethodCount = -1; \
            spMethodNames = 0; \
            spMethodStates = 0; \
            sTestPointsPassed = 0; \
            sTestPointsFailed = 0; \
            sTestPointFailureCount = 0; \
            for(int failureIndex = 0; failureIndex < SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS; failureIndex++)  \
            { \
                sTestPointFailures[failureIndex] = 0; \
            } \
 \<commit_msg>Fixed a bug: == was used where = was meant in an assignment.  Compiler warned, but that is a tough one to spot...<commit_after>// 
//
// Copyright (C) 2010 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2010 SIPez LLC  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
// Author: <NAME>
//         dpetrie AT SIPez DOT com
//////////////////////////////////////////////////////////////////////////////

#ifndef _SipxPortUnitTestClass_h_
#define _SipxPortUnitTestClass_h_

// SYSTEM INCLUDES

// APPLICATION INCLUDES
#include <SipxPortUnitTestEnvironment.h>

// DEFINES

// MACROS
#define CPPUNIT_TEST_SUB_SUITE(CHILD_CLASS_NAME, PARENT_CLASS_NAME) \
    CPPUNIT_TEST_SUITE(CHILD_CLASS_NAME)

#define CPPUNIT_TEST_SUITE(CLASS_NAME) \
    public: \
    /* Not implemented here so actual tests can code constructor 
       and destructors
    CLASS_NAME() : \
        SipxPortUnitTestClass(#CLASS_NAME) \
    { \
    } \
 \
    ~  CLASS_NAME() \
    { \
        char buffer[256]; \
        sprintf(buffer, "Entering ~%s\n", \
                #CLASS_NAME); \
        SipxPortUnitTestEnvironment::printOut(buffer); \
         \
    } */\
 \
    static int getMethodCount() \
    { \
        initializeStatics(); \
        return(sMethodCount); \
    } \
    virtual const char* getCurrentMethodName() const\
    { \
        assert(spMethodNames); \
        return(mCurrentMethodIndex >= 0 && \
               mCurrentMethodIndex < sMethodCount ? \
               spMethodNames[mCurrentMethodIndex] : \
               0); \
    } \
 \
    virtual void incrementTestPointsPassed() \
    { \
        sTestPointsPassed++; \
        SipxPortUnitTestEnvironment::incrementTestPointsPassed(); \
    } \
 \
    static int getPassedTestPointCount() \
    { \
        return(sTestPointsPassed); \
    } \
 \
    static int getFailedTestPointCount() \
    { \
        return(sTestPointsFailed); \
    } \
 \
    virtual void incrementTestPointsFailed() \
    { \
        sTestPointsFailed++; \
        SipxPortUnitTestEnvironment::incrementTestPointsFailed(); \
    } \
 \
    static int getFailureCount() \
    { \
        return(sTestPointFailureCount); \
    } \
 \
    static SipxPortUnitTestPointFailure* getFailure(int failureIndex) \
    { \
        assert(failureIndex >= 0); \
        assert(failureIndex < SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS); \
        return(sTestPointFailures[failureIndex]); \
    } \
 \
    static bool addFailure(SipxPortUnitTestPointFailure* failure) \
    { \
        bool wasAdded = false; \
        if(sTestPointFailureCount < SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS) \
        { \
            sTestPointFailures[sTestPointFailureCount] = failure; \
            sTestPointFailureCount++; \
            wasAdded = true; \
        } \
        else \
        { \
            char message[SIPX_PORT_UNIT_MAX_ERROR_MESSAGE_SIZE]; \
            sprintf(message, "WARNING: maximum failures of %d excedded for class: %s, failure not added: %s\n", \
                    SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS, \
                    failure->getClassName(), failure->getMessage()); \
            SipxPortUnitTestEnvironment::printOut(message); \
        } \
        return(wasAdded); \
    } \
 \
    private: \
    static int sInitialized; \
    static int sInitializedSignature; \
    static int sMethodCount; \
    static char** spMethodNames; \
    static SipxPortTestMethodState* spMethodStates; \
    static int sTestPointsPassed; \
    static int sTestPointsFailed; \
    static int sTestPointFailureCount; \
    static SipxPortUnitTestPointFailure* sTestPointFailures[SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS]; \
 \
    void runAllMethodsFrom(int startMethodIndex) \
    { \
        forEachTestMethod(RUN_ALL_FROM, this, startMethodIndex); \
    } \
 \
    void addFailedTestPoint(const char* fileName, \
                            const char* className, \
                            const char* methodName, \
                            int testPoint, \
                            int lineNumber, \
                            const char* message) \
    { \
        SipxPortUnitTestPointFailure* failure = \
            new SipxPortUnitTestPointFailure(fileName, \
                                             className, \
                                             methodName, \
                                             testPoint, \
                                             lineNumber, \
                                             message); \
        if(!addFailure(failure)) \
        { \
            /* not added. array is full, so clean up */ \
            delete failure; \
            failure = 0; \
        } \
    } \
 \
    static void initializeStatics() \
    { \
        if(!sInitialized || \
           sInitializedSignature != SIPX_PORT_UNIT_TEST_SIGNATURE) \
        { \
            sInitialized = false; \
            sMethodCount = -1; \
            spMethodNames = 0; \
            spMethodStates = 0; \
            sTestPointsPassed = 0; \
            sTestPointsFailed = 0; \
            sTestPointFailureCount = 0; \
            for(int failureIndex = 0; failureIndex < SIPX_PORT_UNIT_MAX_TEST_ERRORS_PER_CLASS; failureIndex++)  \
            { \
                sTestPointFailures[failureIndex] = 0; \
            } \
 \
{'fraction_non_alphanumeric': 0.10882048385578462, 'fraction_numerical': 0.004330226866233644, 'mean_word_length': 1.6310054482417038, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2011352', 'n_tokens_mistral': 3065, 'n_tokens_neox': 3010, 'n_words': 540}