reSIProcate/stack  9694
Defines | Functions
testGperfHash.cxx File Reference
#include <assert.h>
#include <iostream>
#include <sstream>
#include <string.h>
#include <string>
#include "resip/stack/HeaderTypes.hxx"
#include "resip/stack/HeaderHash.hxx"
#include "resip/stack/MethodTypes.hxx"
#include "resip/stack/MethodHash.hxx"
#include "resip/stack/ParameterTypes.hxx"
#include "resip/stack/ParameterHash.hxx"
Include dependency graph for testGperfHash.cxx:

Go to the source code of this file.

Defines

#define RESIPROCATE_SUBSYSTEM   Subsystem::TEST

Functions

static bool testHeaderHash (bool verbose)
static bool testMethodHash (bool verbose)
static bool testParameterHash (bool verbose)
int main ()

Define Documentation

#define RESIPROCATE_SUBSYSTEM   Subsystem::TEST

Definition at line 16 of file testGperfHash.cxx.


Function Documentation

int main ( void  )

Definition at line 111 of file testGperfHash.cxx.

References testHeaderHash(), testMethodHash(), and testParameterHash().

{
  unsigned errors = 0;

  if (testHeaderHash(true))
    errors |= 1;

  if (testMethodHash(true))
    errors |= 2;

  if (testParameterHash(true))
    errors |= 4;

  if (!errors)
    cerr << "All OK" << endl;

  return errors;
}

Here is the call graph for this function:

static bool testHeaderHash ( bool  verbose) [static]

Definition at line 19 of file testGperfHash.cxx.

References resip::Data::c_str(), and resip::Data::size().

Referenced by main().

{
  bool gotErrors = false;

  if (verbose)
    cerr << "Test header hashing" << endl;

  // HeaderNames start from 1, in effect; not sure why.
  //
  int nHeaderNames = sizeof(Headers::HeaderNames) / sizeof(Data);
  if (nHeaderNames != (Headers::MAX_HEADERS + 1))
  {
    if (verbose)
      cerr << "Mismatch: " << nHeaderNames << " header names vs. "
           << Headers::MAX_HEADERS << " header types" << endl;
    gotErrors = true;
  } 
  else
    for (int ht = 0; ht < Headers::MAX_HEADERS; ht++)
    {
      const Data& hName = Headers::getHeaderName(ht);
      Headers::Type ht1 = Headers::getType(hName.c_str(), hName.size());
      if (ht != ht1)
      {
        if (verbose)
          cerr << "Header " << ht << " => " << hName << " => " << ht1 << endl;
        gotErrors = true;
      }
    }

  return gotErrors;
}

Here is the call graph for this function:

static bool testMethodHash ( bool  verbose) [static]

Definition at line 54 of file testGperfHash.cxx.

Referenced by main().

{
  bool gotErrors = false;

  if (verbose)
    cerr << "Test method hashing" << endl;


    for (int mt = 0; mt < MAX_METHODS; mt++)
    {
        const Data& mName = getMethodName(static_cast<MethodTypes>(mt));
//    cout << "Checking " << mName << endl;
      MethodTypes mt1 = getMethodType(mName);
      if (mt != mt1)
      {
        if (verbose)
          cerr << "Method " << mt << " => " << mName << " => " << mt1 << endl;
        gotErrors = true;;
      }
    }

  return gotErrors;
}
static bool testParameterHash ( bool  verbose) [static]

Definition at line 79 of file testGperfHash.cxx.

References resip::Data::c_str(), pName, and resip::Data::size().

Referenced by main().

{
  bool gotErrors = false;
  if (verbose)
    cerr << "Test parameter hashing" << endl;

  int nParameterNames = sizeof(ParameterTypes::ParameterNames) / sizeof(Data);
  if (nParameterNames != ParameterTypes::MAX_PARAMETER)
  {
    if (verbose)
      cerr << "Mismatch: " << nParameterNames << " parameter names vs. "
           << ParameterTypes::MAX_PARAMETER << " parameter types" << endl;
    gotErrors = true;
  } 
  else
    for (int pt = 0; pt < ParameterTypes::MAX_PARAMETER; pt++)
    {
      const Data& pName = ParameterTypes::ParameterNames[pt];
//    cout << "Checking " << pName << endl;
      ParameterTypes::Type pt1 = ParameterTypes::getType(pName.c_str(),
                                                         pName.size());
      if (pt != pt1 && pt1 != ParameterTypes::qopFactory) // qop is weird
      {
        if (verbose)
          cerr << "Parameter " << pt << " => " << pName << " => " << pt1 << endl;
        gotErrors = true;
      }
    }

  return gotErrors;
}

Here is the call graph for this function: