Example #1
0
void
MooseEnumTest::multiTestOne()
{
  MultiMooseEnum mme("one two three four", "two");

  CPPUNIT_ASSERT( mme.contains("one") == false );
  CPPUNIT_ASSERT( mme.contains("two") == true );
  CPPUNIT_ASSERT( mme.contains("three") == false );
  CPPUNIT_ASSERT( mme.contains("four") == false );

  mme.push_back("four");
  CPPUNIT_ASSERT( mme.contains("one") == false );
  CPPUNIT_ASSERT( mme.contains("two") == true );
  CPPUNIT_ASSERT( mme.contains("three") == false );
  CPPUNIT_ASSERT( mme.contains("four") == true );

  // isValid
  CPPUNIT_ASSERT ( mme.isValid() == true );

  mme.clear();
  CPPUNIT_ASSERT ( mme.isValid() == false );

  mme.push_back("one three");
  CPPUNIT_ASSERT( mme.contains("one") == true );
  CPPUNIT_ASSERT( mme.contains("two") == false );
  CPPUNIT_ASSERT( mme.contains("three") == true );
  CPPUNIT_ASSERT( mme.contains("four") == false );

  std::vector<std::string> mvec(2);
  mvec[0] = "one";
  mvec[1] = "two";

  std::set<std::string> mset;
  mset.insert("two");
  mset.insert("three");

  // Assign
  mme = mvec;
  CPPUNIT_ASSERT( mme.contains("one") == true );
  CPPUNIT_ASSERT( mme.contains("two") == true );
  CPPUNIT_ASSERT( mme.contains("three") == false );
  CPPUNIT_ASSERT( mme.contains("four") == false );

  mme = mset;
  CPPUNIT_ASSERT( mme.contains("one") == false );
  CPPUNIT_ASSERT( mme.contains("two") == true );
  CPPUNIT_ASSERT( mme.contains("three") == true );
  CPPUNIT_ASSERT( mme.contains("four") == false );

  // Insert
  mme.push_back(mvec);
  CPPUNIT_ASSERT( mme.contains("one") == true );
  CPPUNIT_ASSERT( mme.contains("two") == true );
  CPPUNIT_ASSERT( mme.contains("three") == true );
  CPPUNIT_ASSERT( mme.contains("four") == false );

  mme.clear();
  mme = "one four";
  CPPUNIT_ASSERT( mme.contains("one") == true );
  CPPUNIT_ASSERT( mme.contains("two") == false );
  CPPUNIT_ASSERT( mme.contains("three") == false );
  CPPUNIT_ASSERT( mme.contains("four") == true );

  mme.push_back("three four");
  CPPUNIT_ASSERT( mme.contains("one") == true );
  CPPUNIT_ASSERT( mme.contains("two") == false );
  CPPUNIT_ASSERT( mme.contains("three") == true );
  CPPUNIT_ASSERT( mme.contains("four") == true );

  // Size
  CPPUNIT_ASSERT( mme.size() == 4 );
  CPPUNIT_ASSERT( mme.unique_items_size() == 3 );

  // All but "two" should be in the Enum
  std::set<std::string> compare_set, return_set, difference;
  for (MooseEnumIterator it = mme.begin(); it != mme.end(); ++it)
    return_set.insert(*it);

  compare_set.insert("ONE");
  compare_set.insert("THREE");
  compare_set.insert("FOUR");


  std::set_symmetric_difference(return_set.begin(), return_set.end(),
                                compare_set.begin(), compare_set.end(),
                                std::inserter(difference, difference.end()));
  CPPUNIT_ASSERT( difference.size() == 0 );

  // Order and indexing
  mme.clear();
  mme = "one two four";
  CPPUNIT_ASSERT( mme.contains("three") == false );

  CPPUNIT_ASSERT( mme[0] == "one" );
  CPPUNIT_ASSERT( mme[1] == "two" );
  CPPUNIT_ASSERT( mme[2] == "four" );
}
Example #2
0
 void callDumpStringForCoverage()
 {
     CPPUNIT_ASSERT(m_path->DumpString().find(L"SCXFilePath") != std::wstring::npos);
     CPPUNIT_ASSERT(m_path->DumpString().find(m_path->GetDirectory()) != std::wstring::npos);
     CPPUNIT_ASSERT(m_path->DumpString().find(m_path->GetFilename()) != std::wstring::npos);
 }
void CNLog2RatioEngineTest::defineOptionsTest()
{
	cout<<endl;
	Verbose::out(1, "****CNLog2RatioEngineTest::defineOptionsTest****");
	CNLog2RatioEngine m_objCNLog2RatioEngine;
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptBool("help")==false);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptInt("verbose")==1);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptBool("version")==false);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("out-dir")==".");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("command-line")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("exec-guid")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("program-name")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("program-company")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("program-version")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("program-cvs-id")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("version-to-report")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("probeset-ids")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("annotation-file")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("expr-summary-file")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("genotype-calls-file")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("genotype-confidences-file")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("genotype-report-file")=="");
    CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptInt("xChromosome")==24);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptInt("yChromosome")==25);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("reference-file")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptBool("call-copynumber-engine")==true);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptBool("log2ratio-hdf5-output")==false);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptBool("log2ratio-text-output")==false);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptInt("mem-usage")==0);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("analysis")=="");
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptInt("gc-correction-bin-count")==25);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptBool("delete-files")==false);
    CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOptBool("log2-input")==false);
    CPPUNIT_ASSERT(m_objCNLog2RatioEngine.getOpt("gc-content-override-file")=="");
}
Example #4
0
    void Vector4Test::testComparisonOperatorGreaterThan() {
        const Vector4f result( 0.0f, 0.0f, 0.0f, 0.0f );
        const Vector4f expected( 1.0f, 1.0f, 1.0f, 1.0f );
		
        CPPUNIT_ASSERT( expected > result );
    }
Example #5
0
	void handleEventTest() {
		Event *e = new EventAA();
		manager.postEvent(e);
		CPPUNIT_ASSERT(handled);
	}
   void QuatGenTest::testQuatMakeRot()
   {
      const float eps = 0.0001f;
      gmtl::Quat<float> q1, q2;
      q1 = gmtl::make<gmtl::Quat<float> >( gmtl::AxisAnglef( gmtl::Math::deg2Rad( 90.0f ), 1.0f, 0.0f, 0.0f ) );
      q2 = gmtl::make<gmtl::Quat<float> >( gmtl::AxisAnglef( gmtl::Math::deg2Rad( 32.0f ), 0.0f, 1.0f, 0.0f ) );
      gmtl::Quat<float> expected_result1( 0.707107f, 0, 0, 0.707107f );
      gmtl::Quat<float> expected_result2( 0, 0.275637f, 0, 0.961262f );

      CPPUNIT_ASSERT( gmtl::isEqual( expected_result1, q1, eps ) );
      CPPUNIT_ASSERT( gmtl::isEqual( expected_result2, q2, eps ) );
      CPPUNIT_ASSERT( gmtl::isNormalized( q1, eps ) );
      CPPUNIT_ASSERT( gmtl::isNormalized( q2, eps ) );

      // values from VR Juggler math lib...
      std::vector< gmtl::Quat<float> > quats;
      quats.push_back( gmtl::Quat<float>( 0, 0, 0, -1       ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.173648f, -0, -0.984808f) );
      quats.push_back( gmtl::Quat<float>( -0, -0.34202f, -0, -0.939693f ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.5f, -0, -0.866025f     ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.642788f, -0, -0.766044f) );
      quats.push_back( gmtl::Quat<float>( -0, -0.766044f, -0, -0.642788f) );
      quats.push_back( gmtl::Quat<float>( -0, -0.866025f, -0, -0.5f     ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.939693f, -0, -0.34202f ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.984808f, -0, -0.173648f) );
      quats.push_back( gmtl::Quat<float>( -0, -1, -0, 0    ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.984808f, -0, 0.173648f ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.939693f, -0, 0.34202f  ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.866025f, -0, 0.5f      ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.766044f, -0, 0.642788f ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.642788f, -0, 0.766044f ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.5f, -0, 0.866025f      ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.34202f, -0, 0.939693f  ) );
      quats.push_back( gmtl::Quat<float>( -0, -0.173648f, -0, 0.984808f ) );
      quats.push_back( gmtl::Quat<float>( 0, 0, 0, 1                  ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.173648f, 0, 0.984808f    ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.34202f, 0, 0.939693f     ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.5f, 0, 0.866025f         ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.642788f, 0, 0.766044f    ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.766044f, 0, 0.642788f    ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.866025f, 0, 0.5f         ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.939693f, 0, 0.34202f     ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.984808f, 0, 0.173648f    ) );
      quats.push_back( gmtl::Quat<float>( 0, 1, 0, 0       ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.984808f, 0, -0.173648f   ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.939693f, 0, -0.34202f    ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.866025f, 0, -0.5f        ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.766044f, 0, -0.642788f   ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.642788f, 0, -0.766044f   ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.5f, 0, -0.866025f        ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.34202f, 0, -0.939693f    ) );
      quats.push_back( gmtl::Quat<float>( 0, 0.173648f, 0, -0.984808f   ) );
      quats.push_back( gmtl::Quat<float>( -0, 0, -0, -1    ) );

      /// @todo check this against another math lib other than VR Juggler...
      int count = 0;
      for (int x = -360; x <= 360; x += 20)
      {
         gmtl::Quat<float> q3;
         CPPUNIT_ASSERT( count >= 0 );
         gmtl::set( q2, gmtl::AxisAnglef( gmtl::Math::deg2Rad( float(x) ), 0.0f, 1.0f, 0.0f ) );
         gmtl::set( q3, gmtl::AxisAnglef( gmtl::Math::deg2Rad( float(x) ), gmtl::Vec3f( 0.0f, 1.0f, 0.0f ) ) );
         CPPUNIT_ASSERT( gmtl::isEqual( quats[count], q2, eps ) );
         CPPUNIT_ASSERT( gmtl::isEqual( q3, q2, eps ) );

         // make sure that makeRot and setRot do the same thing...
         CPPUNIT_ASSERT( gmtl::make<gmtl::Quat<float> >( gmtl::AxisAnglef( gmtl::Math::deg2Rad( float(x) ), 0.0f, 1.0f, 0.0f ) ) == q2 );
         CPPUNIT_ASSERT( gmtl::make<gmtl::Quat<float> >( gmtl::AxisAnglef( gmtl::Math::deg2Rad( float(x) ), gmtl::Vec3f( 0.0f, 1.0f, 0.0f ) ) ) == q3 );
         count++;
      }

   }
Example #7
0
    void Vector4Test::testComparisonOperatorInequality() {
        const Vector4f result( 0.0f, 1.0f, 0.0f, 1.0f );
        const Vector4f expected( 1.0f, 0.0f, 1.0f, 0.0f );
		
        CPPUNIT_ASSERT( expected != result );
    }
//----------------------------------------------------------------------------
void medOpMML3ParameterViewTest::CompareImages(mafString test_name)
//----------------------------------------------------------------------------
{
  char *file = __FILE__;
  std::string name(file);
  int slashIndex =  name.find_last_of('\\');

  name = name.substr(slashIndex+1);

  int pointIndex =  name.find_last_of('.');
  name = name.substr(0, pointIndex);

  mafString controlOriginFile=MED_DATA_ROOT;
  //controlOriginFile << "/Test_OpMML3ParameterView/";
  controlOriginFile << "/";
  controlOriginFile << name.c_str();
  controlOriginFile << "_";
  controlOriginFile << "image";
  controlOriginFile << test_name.GetCStr();
  controlOriginFile << ".jpg";

  fstream controlStream;
  controlStream.open(controlOriginFile.GetCStr()); 

  // visualization control
  m_RenderWindow->OffScreenRenderingOn();
  vtkWindowToImageFilter *w2i;
  vtkNEW(w2i);
  w2i->SetInput(m_RenderWindow);
  //w2i->SetMagnification(magnification);
  w2i->Update();
  m_RenderWindow->OffScreenRenderingOff();

  //write comparing image
  vtkJPEGWriter *w;
  vtkNEW(w);
  w->SetInput(w2i->GetOutput());
  mafString imageFile=MED_DATA_ROOT;

  if(!controlStream)
  {
    imageFile << "/";
    imageFile << name.c_str();
    imageFile << "_";
    imageFile << "image";
  }
  else
  {
    imageFile << "/";
    imageFile << name.c_str();
    imageFile << "_";
    imageFile << "comp";
  }

  imageFile << test_name.GetCStr();
  imageFile << ".jpg";
  w->SetFileName(imageFile.GetCStr());
  w->Write();

  if(!controlStream)
  {
    controlStream.close();
    vtkDEL(w);
    vtkDEL(w2i);

    return;
  }
  controlStream.close();

  //read original Image
  vtkJPEGReader *rO;
  vtkNEW(rO);
  mafString imageFileOrig=MED_DATA_ROOT;
  imageFileOrig << "/";
  imageFileOrig << name.c_str();
  imageFileOrig << "_";
  imageFileOrig << "image";
  imageFileOrig << test_name.GetCStr();
  imageFileOrig << ".jpg";
  rO->SetFileName(imageFileOrig.GetCStr());
  rO->Update();

  vtkImageData *imDataOrig = rO->GetOutput();

  //read compared image
  vtkJPEGReader *rC;
  vtkNEW(rC);
  rC->SetFileName(imageFile.GetCStr());
  rC->Update();

  vtkImageData *imDataComp = rC->GetOutput();


  vtkImageMathematics *imageMath = vtkImageMathematics::New();
  imageMath->SetInput1(imDataOrig);
  imageMath->SetInput2(imDataComp);
  imageMath->SetOperationToSubtract();
  imageMath->Update();

  double srR[2] = {-1,1};
  imageMath->GetOutput()->GetPointData()->GetScalars()->GetRange(srR);

  CPPUNIT_ASSERT(srR[0] == 0.0 && srR[1] == 0.0);

  // end visualization control
  vtkDEL(imageMath);
  vtkDEL(rC);
  vtkDEL(rO);

  vtkDEL(w);
  vtkDEL(w2i);
}
void DHTests::testSerialisation()
{
	// Generate 1024-bit parameters for testing
	DHParameters* p;
	AsymmetricParameters** ap = (AsymmetricParameters**) &p;

	//CPPUNIT_ASSERT(dh->generateParameters(ap, (void*) 1024));
	// changed for 512-bit for speed...
#ifndef WITH_BOTAN
	CPPUNIT_ASSERT(dh->generateParameters(ap, (void*) 1024));
#else
	CPPUNIT_ASSERT(dh->generateParameters(ap, (void*) 512));
#endif

	// Set a fixed private value length
	p->setXBitLength(128);

	// Serialise the parameters
	ByteString serialisedParams = p->serialise();

	// Deserialise the parameters
	AsymmetricParameters* dP;

	CPPUNIT_ASSERT(dh->reconstructParameters(&dP, serialisedParams));

	CPPUNIT_ASSERT(dP->areOfType(DHParameters::type));

	DHParameters* ddP = (DHParameters*) dP;

	CPPUNIT_ASSERT(p->getP() == ddP->getP());
	CPPUNIT_ASSERT(p->getG() == ddP->getG());
	CPPUNIT_ASSERT(p->getXBitLength() == ddP->getXBitLength());

	// Generate a key-pair
	AsymmetricKeyPair* kp;

	CPPUNIT_ASSERT(dh->generateKeyPair(&kp, dP));

	// Serialise the key-pair
	ByteString serialisedKP = kp->serialise();

	// Deserialise the key-pair
	AsymmetricKeyPair* dKP;

	CPPUNIT_ASSERT(dh->reconstructKeyPair(&dKP, serialisedKP));

	// Check the deserialised key-pair
	DHPrivateKey* privKey = (DHPrivateKey*) kp->getPrivateKey();
	DHPublicKey* pubKey = (DHPublicKey*) kp->getPublicKey();

	DHPrivateKey* dPrivKey = (DHPrivateKey*) dKP->getPrivateKey();
	DHPublicKey* dPubKey = (DHPublicKey*) dKP->getPublicKey();

	CPPUNIT_ASSERT(privKey->getP() == dPrivKey->getP());
	CPPUNIT_ASSERT(privKey->getG() == dPrivKey->getG());
	CPPUNIT_ASSERT(privKey->getX() == dPrivKey->getX());

	CPPUNIT_ASSERT(pubKey->getP() == dPubKey->getP());
	CPPUNIT_ASSERT(pubKey->getG() == dPubKey->getG());
	CPPUNIT_ASSERT(pubKey->getY() == dPubKey->getY());

	dh->recycleParameters(p);
	dh->recycleParameters(dP);
	dh->recycleKeyPair(kp);
	dh->recycleKeyPair(dKP);
}
Example #10
0
void WoWBrainTest::testGetAIPlane() {
    CPPUNIT_ASSERT(ai->getAIPlane()->getId() == 1);
}
Example #11
0
void WoWBrainTest::testNextValidMoves() {
    CPPUNIT_ASSERT(false);
}
      void testAllEmergencyPermutations()
      {
         FallbackRulesUrlMapping* urlmap;
         ResultSet registrations;
         UtlString actual;

         CPPUNIT_ASSERT( urlmap = new FallbackRulesUrlMapping() );
         UtlString simpleXml;
         mFileTestContext->inputFilePath("fallbackrules.xml", simpleXml);
         CPPUNIT_ASSERT( urlmap->loadMappings(simpleXml.data() ) == OS_SUCCESS );

         // permutations for the 'boston' location
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         // permutation for the 'seattle' location
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();
         
         // permutation for the default location
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Kookamonga"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Kookamonga"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Kookamonga"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Kookamonga"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Kookamonga"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Kookamonga"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Kookamonga"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Kookamonga"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Kookamonga"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString(""),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();
         
         delete urlmap;
      }
      void testAllLongDistancePermutations()
      {
         FallbackRulesUrlMapping* urlmap;
         ResultSet registrations;
         UtlString actual;

         CPPUNIT_ASSERT( urlmap = new FallbackRulesUrlMapping() );
         UtlString simpleXml;
         mFileTestContext->inputFilePath("fallbackrules.xml", simpleXml);
         CPPUNIT_ASSERT( urlmap->loadMappings(simpleXml.data() ) == OS_SUCCESS );

         // permutations for the 'boston' location
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 2 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.9",actual);
         getResult( registrations, 1, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.8",actual);
         registrations.destroyAll();
         
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 2 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.9",actual);
         getResult( registrations, 1, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.8",actual);
         registrations.destroyAll();
         
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 2 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.9",actual);
         getResult( registrations, 1, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.8",actual);
         registrations.destroyAll();

         // permutations for the 'seattle' location
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 2 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.9",actual);
         getResult( registrations, 1, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.7",actual);
         registrations.destroyAll();
         
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 2 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.9",actual);
         getResult( registrations, 1, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.7",actual);
         registrations.destroyAll();
         
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("seattle"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 2 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.9",actual);
         getResult( registrations, 1, "contact", actual);
         ASSERT_STR_EQUAL("<sip:[email protected]>;q=0.7",actual);
         registrations.destroyAll();

         // permutations for the other locations
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("walla-walla"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();
         
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString(""),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();
         
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("ogden"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         delete urlmap;
      }
      void testAll800Permutations()
      {
         FallbackRulesUrlMapping* urlmap;
         ResultSet registrations;
         UtlString actual;

         CPPUNIT_ASSERT( urlmap = new FallbackRulesUrlMapping() );
         UtlString simpleXml;
         mFileTestContext->inputFilePath("fallbackrules.xml", simpleXml);
         CPPUNIT_ASSERT( urlmap->loadMappings(simpleXml.data() ) == OS_SUCCESS );

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations
                                ) == OS_SUCCESS );

         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("regina"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString(""),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("new-york"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("DC"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("Philly"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString(""),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("miami"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("orlando"),
                                registrations
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 1 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         delete urlmap;
      }
void TestSpinNetwork::test_propose_step()
{
  // Create a random number generator
  Mocasinns::Random::Boost_MT19937 rng;
  
  // Define boolean variables indicating whether an index was tried to flip
  bool dynamic_index_0_found = false; bool static_index_0_found = false;
  bool dynamic_index_1_found = false; bool static_index_1_found = false;
  bool dynamic_index_2_found = false; bool static_index_2_found = false;

  // Suggest a lot of steps and test them
  for (unsigned int i = 0; i < 1000; ++i)
  {
    // Propose the two steps
    SpinNetworkStep<IsingSpin, std::vector<IsingSpin*> > step_dynamic
      = testnetwork_dynamic->propose_step(&rng);
    SpinNetworkStep<IsingSpin, std::array<IsingSpin*, 2> > step_static
      = testnetwork_static->propose_step(&rng);

    // Check the old and the new spins
    CPPUNIT_ASSERT(step_dynamic.get_old_spin() == IsingSpin(1));
    CPPUNIT_ASSERT(step_dynamic.get_new_spin() == IsingSpin(-1));
    CPPUNIT_ASSERT(step_static.get_old_spin() == IsingSpin(1));
    CPPUNIT_ASSERT(step_static.get_new_spin() == IsingSpin(-1));

    // Check the range of the indizes
    CPPUNIT_ASSERT(step_dynamic.get_flip_index() <= 2);
    CPPUNIT_ASSERT(step_static.get_flip_index() <= 2);

    // Check the indizes
    if (step_dynamic.get_flip_index() == 0) dynamic_index_0_found = true;
    if (step_dynamic.get_flip_index() == 1) dynamic_index_1_found = true;
    if (step_dynamic.get_flip_index() == 2) dynamic_index_2_found = true;
    if (step_static.get_flip_index() == 0) static_index_0_found = true;
    if (step_static.get_flip_index() == 1) static_index_1_found = true;
    if (step_static.get_flip_index() == 2) static_index_2_found = true;
  }

  CPPUNIT_ASSERT(dynamic_index_0_found);
  CPPUNIT_ASSERT(dynamic_index_1_found);
  CPPUNIT_ASSERT(dynamic_index_2_found);
  CPPUNIT_ASSERT(static_index_0_found);
  CPPUNIT_ASSERT(static_index_1_found);
  CPPUNIT_ASSERT(static_index_2_found);
}
void DHTests::testPKCS8()
{
	// Generate 1024-bit parameters for testing
	AsymmetricParameters* p;

	//CPPUNIT_ASSERT(dh->generateParameters(&p, (void*) 1024));
	// changed for 512-bit for speed...
#ifndef WITH_BOTAN
	CPPUNIT_ASSERT(dh->generateParameters(&p, (void*) 1024));
#else
	CPPUNIT_ASSERT(dh->generateParameters(&p, (void*) 512));
#endif

	// Generate a key-pair
	AsymmetricKeyPair* kp;

	CPPUNIT_ASSERT(dh->generateKeyPair(&kp, p));
	CPPUNIT_ASSERT(kp != NULL);

	DHPrivateKey* priv = (DHPrivateKey*) kp->getPrivateKey();
	CPPUNIT_ASSERT(priv != NULL);

	// Encode and decode the private key
	ByteString pkcs8 = priv->PKCS8Encode();
	CPPUNIT_ASSERT(pkcs8.size() != 0);

	DHPrivateKey* dPriv = (DHPrivateKey*) dh->newPrivateKey();
	CPPUNIT_ASSERT(dPriv != NULL);

	CPPUNIT_ASSERT(dPriv->PKCS8Decode(pkcs8));


	CPPUNIT_ASSERT(priv->getP() == dPriv->getP());
	CPPUNIT_ASSERT(priv->getG() == dPriv->getG());
	CPPUNIT_ASSERT(priv->getX() == dPriv->getX());

	dh->recycleParameters(p);
	dh->recycleKeyPair(kp);
	dh->recyclePrivateKey(dPriv);
}
   void QuatGenMetricTest::testGenTimingSetRot()
   {
      double bokd = 1;
      float bokf = 1;
      gmtl::Quat<double> q1;
      const long iters(25000);
      CPPUNIT_METRIC_START_TIMING();

      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q1, gmtl::makeNormal( gmtl::AxisAngled( bokd, bokd, bokd, bokd ) ) );
         bokd += q1[2];
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatd,axisangled)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      gmtl::Quat<float> q2; bokf = 1.0f;
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q2, gmtl::makeNormal( gmtl::AxisAnglef( bokf, bokf, bokf, bokf ) ) );
         bokf -= q2[3];
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatf,axisanglef)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%


      gmtl::Quat<double> q3; bokd = 1.0f;
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q3, gmtl::makeNormal( gmtl::AxisAngled( bokd, gmtl::Vec<double, 3>( bokd, bokd, bokd ) ) ) );
         bokd *= q3[1] + 1.2;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatd,axisangled(r,vec))", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      gmtl::Quat<float> q4; bokf = 1.0f;
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::set( q4, gmtl::makeNormal( gmtl::AxisAnglef( bokf, gmtl::Vec<float, 3>( bokf, bokf, bokf ) ) ) );
         bokf += q4[1] + 1.2f;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatf,axisanglef(r,vec))", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%


      gmtl::Quat<double> q5;
      gmtl::Vec<double, 3> v4(1,2,3), v5(1,2,3);
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::setRot( q5, gmtl::makeNormal( v4 ), gmtl::makeNormal( v5 ) );
         v4[2] += q5[1] + 1.2;
         v5[0] -= q5[2] + 1.2;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatd,vec3d,vec3d)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      gmtl::Quat<float> q6;
      gmtl::Vec<float, 3> v6(1,2,3), v7(1,2,3);
      CPPUNIT_METRIC_START_TIMING();
      for (long iter = 0; iter < iters; ++iter)
      {
         gmtl::setRot( q6, gmtl::makeNormal( v6 ), gmtl::makeNormal( v7 ) );
         v6[2] += q6[1] + 1.2f;
         v7[0] -= q6[2] + 1.2f;
      }
      CPPUNIT_METRIC_STOP_TIMING();
      CPPUNIT_ASSERT_METRIC_TIMING_LE( "QuatGenTest/setRot(quatf,vec3f,vec3f)", iters, 0.075f, 0.1f);  // warn at 7.5%, error at 10%

      // force intelligent compilers to do all the iterations (ie. to not optimize them out),
      // by using the variables computed...
      CPPUNIT_ASSERT( bokf != 0.998f );
      CPPUNIT_ASSERT( bokd != 0.0998 );
      CPPUNIT_ASSERT( q1[0] != 10000.0f );
      CPPUNIT_ASSERT( q2[1] != 10000.0f );
      CPPUNIT_ASSERT( q3[2] != 10000.0f );
      CPPUNIT_ASSERT( q4[3] != 10000.0f );
      CPPUNIT_ASSERT( q5[0] != 10000.0f );
      CPPUNIT_ASSERT( q6[1] != 10000.0f );
   }
Example #18
0
	void operator()(const CoOrd next) {
		int dx = std::abs(next.first - last.first);
		int dy = std::abs(next.second - last.second);
		CPPUNIT_ASSERT(dx < 2 && dy < 2 && (dx || dy));
		last = next;
	}
void NavigationSeriesTest::navigationTest()
{
    CPPUNIT_ASSERT(m_series);
    ::fwMedData::NavigationSeries::ContainerType positions =
    {
        {0., {-514.1606513019431, -94.68116795798758, 979.3785055174628}}
    };

    ::fwMedData::NavigationSeries::ContainerType move =
    {
        {0., {0.897820633950464, 0.13607544320686907, -1.2769419285130967}},
        {1421.375, {2.322431935080602, 0.33708203932328956, -3.734284956660633}},
        {2114.208, {2.43713135678714, -0.049220088700801926, -3.266794030753196}},
        {3377.9159999999997, {0., 0., 0.}},
        {4027.6536502546687, {-3.964310130780936, 0.08006285575503613, 5.313864037415808}},
        {6237.149579831932, {0., 0., 0.}},
        {6500.074702886248, {-0.8058588959846187, 1.6088833889257592, -2.2406369414514837}},
        {7616.651952461799, {0.15881288125106394, 0.9634983958585909, -3.792280054764281}},
        {9291.517826825127, {15.00876504273313, 1.948698699541007, 9.621351972786318}},
        {10328.339558573854, {8.746762102220163, -1.3252231011236748, 0.40990799919194243}},
        {11344.944, {3.107379091978582, 0.24758149132857085, -1.7704233405817775}},
        {13717.94906621392, {-14.868514648384936, -0.06864726970614742, -1.8512522029189045}},
        {14874.404074702887, {-2.1505985395333633, 0.0025699595738454374, -0.5800507110513734}},
        {15472.570458404074, {0.5463244285267206, -0.009449336194383946, -4.067785389892101}},
        {18862.179966044143, {0., 0., 0.}},
        {20576.923599320886, {-1.4763543428185393, 0.6215147468157091, 4.983670944496179}},
        {23208.855687606112, {0., 0., 0.}}
    };

    ::fwMedData::NavigationSeries::ContainerType lookAt =
    {
        {0., {216.48659596562175, -109.43725495319805, 0.}},
        {4027.6536502546687, {206.6271751068543, -90.3143606602177, -7.6435594203111314}},
        {6500.074702886248, {206.6271751068543, -90.3143606602177, -7.6435594203111314}}
    };

    // Test add API
    for(const auto& elt : positions)
    {
        m_series->addPosition(elt.first, elt.second);
    }
    for(const auto& elt : move)
    {
        m_series->addMove(elt.first, elt.second);
    }
    for(const auto& elt : lookAt)
    {
        m_series->addLookAt(elt.first, elt.second);
    }
    CPPUNIT_ASSERT_EQUAL(positions.size(), m_series->getPositionMap().size());
    CPPUNIT_ASSERT_EQUAL(move.size(), m_series->getMoveMap().size());
    CPPUNIT_ASSERT_EQUAL(lookAt.size(), m_series->getLookAtMap().size());

    CPPUNIT_ASSERT(positions == m_series->getPositionMap());
    CPPUNIT_ASSERT(move == m_series->getMoveMap());
    CPPUNIT_ASSERT(lookAt == m_series->getLookAtMap());

    // Create Path
    const ::boost::filesystem::path path = ::fwTools::System::getTemporaryFolder() / "navigationtest";
    ::boost::filesystem::create_directories(path);

    const std::string jsonzFile = "NavigationSeriesTest.jsonz";
    ::fwAtoms::Object::sptr atom1 = ::fwAtomConversion::convert(m_series);
    writeNavigation((path/jsonzFile), atom1);

    ::fwAtoms::Object::sptr atom2 = readNavigation(path/jsonzFile);

    ::fwData::Object::sptr object;
    ::fwMedData::NavigationSeries::sptr navigationSeries;

    object           = ::fwAtomConversion::convert(atom2, ::fwAtomConversion::AtomVisitor::ChangePolicy());
    navigationSeries = ::fwMedData::NavigationSeries::dynamicCast(object);

    // Test get API
    CPPUNIT_ASSERT(navigationSeries);
    CPPUNIT_ASSERT_EQUAL(positions.size(), navigationSeries->getPositionMap().size());
    CPPUNIT_ASSERT_EQUAL(move.size(), navigationSeries->getMoveMap().size());
    CPPUNIT_ASSERT_EQUAL(lookAt.size(), navigationSeries->getLookAtMap().size());

    CPPUNIT_ASSERT(positions == navigationSeries->getPositionMap());
    CPPUNIT_ASSERT(move == navigationSeries->getMoveMap());
    CPPUNIT_ASSERT(lookAt == navigationSeries->getLookAtMap());

    // Test erase API
    double timestamp = positions.begin()->first;
    navigationSeries->erasePosition(timestamp);
    CPPUNIT_ASSERT(navigationSeries->getPositionMap().find(timestamp) == navigationSeries->getPositionMap().end());

    timestamp = move.begin()->first;
    navigationSeries->eraseMove(timestamp);
    CPPUNIT_ASSERT(navigationSeries->getMoveMap().find(timestamp) == navigationSeries->getMoveMap().end());

    timestamp = lookAt.begin()->first;
    navigationSeries->eraseLookAt(timestamp);
    CPPUNIT_ASSERT(navigationSeries->getLookAtMap().find(timestamp) == navigationSeries->getLookAtMap().end());

    // Test clear API
    navigationSeries->clearPosition();
    CPPUNIT_ASSERT(navigationSeries->getPositionMap().empty());

    navigationSeries->clearMove();
    CPPUNIT_ASSERT(navigationSeries->getMoveMap().empty());

    navigationSeries->clearLookAt();
    CPPUNIT_ASSERT(navigationSeries->getLookAtMap().empty());
}
void FdoSpatialContextTest::CreateSchema( FdoIConnection* connection, bool hasMetaSchema )
{
    FdoPtr<FdoFeatureSchema> schema;

    if ( hasMetaSchema ) {
    	/* A schema with dictionary */
        schema = FdoFeatureSchema::Create( L"ScTest", L"" );
    }
    else {
	    FdoPtr<FdoIDescribeSchema> cmd = (FdoIDescribeSchema*) connection->CreateCommand(FdoCommandType_DescribeSchema);
	    FdoFeatureSchemasP schemas = cmd->Execute();

        CPPUNIT_ASSERT( schemas->GetCount() > 0 );

        schema = schemas->FindItem(L"dbo");
        if ( !schema ) 
            schema = schemas->GetItem(0);
    }

	FdoPtr<FdoIApplySchema>  pCmd = (FdoIApplySchema*) connection->CreateCommand(FdoCommandType_ApplySchema);

	/* An abstract base class */

	FdoPtr<FdoFeatureClass> pClass = FdoFeatureClass::Create( L"ClassB1", L"" );
	FdoClassesP(schema->GetClasses())->Add( pClass );

	FdoPtr<FdoDataPropertyDefinition> pProp = FdoDataPropertyDefinition::Create( L"Prop1", L"" );
	pProp->SetDataType( FdoDataType_Int64 );
	pProp->SetNullable(false);
    pProp->SetIsAutoGenerated(true);
	FdoPropertiesP(pClass->GetProperties())->Add( pProp );
	FdoDataPropertiesP(pClass->GetIdentityProperties())->Add( pProp );

	// Test geometry property

	FdoPtr<FdoGeometricPropertyDefinition> pGeomProp = FdoGeometricPropertyDefinition::Create( L"Geometry1", L"" );
	pGeomProp->SetGeometryTypes( FdoGeometricType_Point | FdoGeometricType_Curve );
    pGeomProp->SetSpatialContextAssociation(L"Bermuda");
    FdoPropertiesP(pClass->GetProperties())->Add( pGeomProp );
	pClass->SetGeometryProperty( pGeomProp );

	pGeomProp = FdoGeometricPropertyDefinition::Create( L"Geometry2", L"" );
	pGeomProp->SetGeometryTypes( FdoGeometricType_Point | FdoGeometricType_Curve );
    pGeomProp->SetSpatialContextAssociation(L"Rectangular");
    FdoPropertiesP(pClass->GetProperties())->Add( pGeomProp );

	pGeomProp = FdoGeometricPropertyDefinition::Create( L"Geometry3", L"" );
	pGeomProp->SetGeometryTypes( FdoGeometricType_Point | FdoGeometricType_Curve );
    pGeomProp->SetSpatialContextAssociation(L"South");
    FdoPropertiesP(pClass->GetProperties())->Add( pGeomProp );

	pGeomProp = FdoGeometricPropertyDefinition::Create( L"Geometry4", L"" );
	pGeomProp->SetGeometryTypes( FdoGeometricType_Point | FdoGeometricType_Curve );
    pGeomProp->SetSpatialContextAssociation(L"Bermuda Duplicate");
    FdoPropertiesP(pClass->GetProperties())->Add( pGeomProp );

	pGeomProp = FdoGeometricPropertyDefinition::Create( L"Geometry5", L"" );
	pGeomProp->SetGeometryTypes( FdoGeometricType_Point | FdoGeometricType_Curve );
    pGeomProp->SetSpatialContextAssociation(L"sc_1");
    FdoPropertiesP(pClass->GetProperties())->Add( pGeomProp );

	pCmd->SetFeatureSchema( schema );
	pCmd->Execute();
}
Example #21
0
    void Vector4Test::testComparisonOperatorLessThan() {
        const Vector4f result( 0.0f, 0.0f, 0.0f, 0.0f );
        const Vector4f expected( -1.0f, -1.0f, -1.0f, -1.0f );
		
        CPPUNIT_ASSERT( expected < result );
    }
void FdoSpatialContextTest::DoTest( bool hasMetaSchema )
{
    FdoPtr<FdoIConnection> connection;
    StaticConnection* staticConn = NULL;

    try {
        if ( !hasMetaSchema ) {
            staticConn = UnitTestUtil::NewStaticConnection();
            staticConn->connect();
            UnitTestUtil::CreateDBNoMeta( 
                staticConn->CreateSchemaManager(),
                UnitTestUtil::GetEnviron("datastore", DB_NAME_SUFFIX)
            );
        }


        // delete, re-create and open the datastore
		printf( "Initializing Connection ... \n" );
		connection = UnitTestUtil::CreateConnection(
			hasMetaSchema,
			hasMetaSchema,
            DB_NAME_SUFFIX,
            0,
            NULL,
            0
		);

		printf( "Creating Spatial Contexts ... \n" );

        UnitTestUtil::CreateSpatialContext( connection, L"Bermuda", L"Bermuda 1957", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Rectangular", L"", 0, 0, 1000, 1000 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Bermuda Duplicate", L"Bermuda 1957", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Luxembourg Delete", L"Luxembourg 1930", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"South", L"Australian Antarctic", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"sc_2", L"Puerto Rico", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"South Delete", L"Australian Antarctic", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"sc_1", L"NAD27", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"South Duplicate", L"Australian Antarctic", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Liberia by WKT", L"", 0, 0, 10, 10, L"GEOGCS[\"Liberia 1964\", DATUM[\"Liberia 1964\", ELLIPSOID[\"Clarke 1880 (RGS)\", 6378249.145, 293.465]], PRIMEM[\"Greenwich\", 0], UNIT[\"Degree\", 0.0174532925199433]]" ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Qatar wrong name", L"Bermuda 1957", 0, 0, 10, 10, L"GEOGCS[\"Qatar 1974\", DATUM[\"Qatar 1974\", ELLIPSOID[\"International 1924\", 6378388, 297]], PRIMEM[\"Greenwich\", 0], UNIT[\"Degree\", 0.0174532925199433]]" ); 
        UnitTestUtil::CreateSpatialContext( connection, L"California", L"CA-I", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Bermuda Mentor", L"Bermuda.LL", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Mentor by WKT", L"", 0, 0, 10, 10, L"PROJCS[\"Quebec test\",GEOGCS[\"For testing only\",DATUM[\"Test\",SPHEROID[\"NAD 27\",6300000,123.465,]]]]" ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Rectangular (Metre)", L"XY-M", 0, 0, 10, 10); 
        UnitTestUtil::CreateSpatialContext( connection, L"Rectangular (Feet)", L"XY-FT", 0, 0, 10, 10); 

        connection->Close();
        connection->Open();

		printf( "Deleting Spatial Contexts ... \n" );

        UnitTestUtil::DeleteSpatialContext( connection, L"Luxembourg Delete" );
        UnitTestUtil::DeleteSpatialContext( connection, L"South Delete" );

        connection->Close();
        connection->Open();

        CreateSchema( connection, hasMetaSchema );

		printf( "Writing output ... \n" );

        FdoStringP datastore = UnitTestUtil::GetEnviron("datastore", DB_NAME_SUFFIX);

        FdoIoMemoryStreamP stream1 = FdoIoMemoryStream::Create();

        FdoXmlSpatialContextFlagsP flags = FdoXmlSpatialContextFlags::Create(
            L"fdo.osgeo.org/schemas/feature",
            FdoXmlFlags::ErrorLevel_Normal,
            true,
            FdoXmlSpatialContextFlags::ConflictOption_Add,
            true
        );

        UnitTestUtil::ExportDb( 
            connection, 
            stream1, 
            flags,
            false, 
            FdoStringP(L"Fdo") + datastore
        );

   		UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(1, hasMetaSchema, false) ) );

        UnitTestUtil::CheckOutput( 
            GenFileName( 1, hasMetaSchema, true ),
            UnitTestUtil::GetOutputFileName( GenFileName(1, hasMetaSchema, false) )
        );

        InsertFeatures( connection );

        stream1 = FdoIoMemoryStream::Create();

        UnitTestUtil::ExportDb( 
            connection, 
            stream1, 
            flags,
            false, 
            FdoStringP(L"Fdo") + datastore,
            L"AutoGen",
            true
        );

   		UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(2, hasMetaSchema, false) ) );

        UnitTestUtil::CheckOutput( 
            GenFileName( 2, hasMetaSchema, true ),
            UnitTestUtil::GetOutputFileName( GenFileName(2, hasMetaSchema, false) )
        );

        if ( !hasMetaSchema ) {
            CreateTables( staticConn, datastore );

            connection->Close();
            connection->Open();

            stream1 = FdoIoMemoryStream::Create();

            UnitTestUtil::ExportDb( 
                connection, 
                stream1, 
                flags,
                false, 
                FdoStringP(L"Fdo") + datastore,
                L"AutoGen",
                true
            );

   		    UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) ) );

            UnitTestUtil::CheckOutput( 
                GenFileName( 3, hasMetaSchema, true ),
                UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) )
            );


            try {
                UnitTestUtil::CreateSpatialContext( connection, L"Nowhere", L"JunkCS", 0, 0, 10, 10 ); 
                CPPUNIT_FAIL( "Setting unsupported coordinate system by name supposed to fail" );
            }
            catch (FdoException* e ) {
#ifdef _WIN32
#ifdef _DEBUG
                FdoStringP expectedMessage = L" Error creating spatial context Nowhere, coordinate system JunkCS is not in current datastore. ";
                FdoString* pMessage = wcschr( e->GetExceptionMessage(), ')' );
                if (pMessage) pMessage++;
#else
                FdoStringP expectedMessage = L"Error creating spatial context Nowhere, coordinate system JunkCS is not in current datastore. ";
                FdoString* pMessage = e->GetExceptionMessage();
#endif
                CPPUNIT_ASSERT( pMessage && expectedMessage.ICompare(pMessage) == 0 );
#endif
                FDO_SAFE_RELEASE(e);
            }

            try {
                UnitTestUtil::CreateSpatialContext( connection, L"California2", L"", 0, 0, 10, 10, L"PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]" ); 
                CPPUNIT_FAIL( "Setting unsupported coordinate system by wkt supposed to fail" );
            }
            catch (FdoException* e ) {
#ifdef _WIN32
#ifdef _DEBUG
                FdoStringP expectedMessage = L" Error creating spatial context California2, coordinate system catalog does not contain entry for WKT 'PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]' ";
                FdoString* pMessage = wcschr( e->GetExceptionMessage(), ')' );
                if (pMessage) pMessage++;
#else
                FdoStringP expectedMessage = L"Error creating spatial context California2, coordinate system catalog does not contain entry for WKT 'PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]' ";
                FdoString* pMessage = e->GetExceptionMessage();
#endif
                CPPUNIT_ASSERT( pMessage && expectedMessage.ICompare(pMessage) == 0 );
#endif
                FDO_SAFE_RELEASE(e);
            }
        }
        else {
            UnitTestUtil::CreateSpatialContext( connection, L"Nowhere", L"JunkCS", 0, 0, 10, 10 ); 
            UnitTestUtil::CreateSpatialContext( connection, L"California2", L"CA_I", 0, 0, 10, 10, L"PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]" ); 

            stream1 = FdoIoMemoryStream::Create();
            UnitTestUtil::ExportDb( 
                connection, 
                stream1, 
                flags,
                false, 
                FdoStringP(L"Fdo") + datastore,
                L"AutoGen",
                true
            );

            UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) ) );

            UnitTestUtil::CheckOutput( 
                GenFileName( 3, hasMetaSchema, true ),
                UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) )
            );

        }

        delete staticConn;
        connection->Close();
    }
    catch ( ... )
    {
        try {
            if ( staticConn ) delete staticConn;
            if ( connection ) connection->Close();
        }
        catch ( ... ) {
        }

        throw;
    }
}
Example #23
0
  void TestTempMethods()
  {
    std::string tmpPath = mitk::IOUtil::GetTempPath();
    CPPUNIT_ASSERT(!tmpPath.empty());

    std::ofstream tmpFile;
    std::string tmpFilePath = mitk::IOUtil::CreateTemporaryFile(tmpFile);
    CPPUNIT_ASSERT(tmpFile && tmpFile.is_open());
    CPPUNIT_ASSERT(tmpFilePath.size() > tmpPath.size());
    CPPUNIT_ASSERT(tmpFilePath.substr(0, tmpPath.size()) == tmpPath);

    tmpFile.close();
    CPPUNIT_ASSERT(std::remove(tmpFilePath.c_str()) == 0);

    std::string programPath = mitk::IOUtil::GetProgramPath();
    CPPUNIT_ASSERT(!programPath.empty());
    std::ofstream tmpFile2;
    std::string tmpFilePath2 = mitk::IOUtil::CreateTemporaryFile(tmpFile2, "my-XXXXXX", programPath);
    CPPUNIT_ASSERT(tmpFile2 && tmpFile2.is_open());
    CPPUNIT_ASSERT(tmpFilePath2.size() > programPath.size());
    CPPUNIT_ASSERT(tmpFilePath2.substr(0, programPath.size()) == programPath);
    tmpFile2.close();
    CPPUNIT_ASSERT(std::remove(tmpFilePath2.c_str()) == 0);

    std::ofstream tmpFile3;
    std::string tmpFilePath3 =
      mitk::IOUtil::CreateTemporaryFile(tmpFile3, std::ios_base::binary, "my-XXXXXX.TXT", programPath);
    CPPUNIT_ASSERT(tmpFile3 && tmpFile3.is_open());
    CPPUNIT_ASSERT(tmpFilePath3.size() > programPath.size());
    CPPUNIT_ASSERT(tmpFilePath3.substr(0, programPath.size()) == programPath);
    CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 13, 3) == "my-");
    CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 4) == ".TXT");
    tmpFile3.close();
    // CPPUNIT_ASSERT(std::remove(tmpFilePath3.c_str()) == 0)

    std::string tmpFilePath4 = mitk::IOUtil::CreateTemporaryFile();
    std::ofstream file;
    file.open(tmpFilePath4.c_str());
    CPPUNIT_ASSERT_MESSAGE("Testing if file exists after CreateTemporaryFile()", file.is_open());

    CPPUNIT_ASSERT_THROW(mitk::IOUtil::CreateTemporaryFile(tmpFile2, "XX"), mitk::Exception);

    std::string tmpDir = mitk::IOUtil::CreateTemporaryDirectory();
    CPPUNIT_ASSERT(tmpDir.size() > tmpPath.size());
    CPPUNIT_ASSERT(tmpDir.substr(0, tmpPath.size()) == tmpPath);
    CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir.c_str()));

    std::string tmpDir2 = mitk::IOUtil::CreateTemporaryDirectory("my-XXXXXX", programPath);
    CPPUNIT_ASSERT(tmpDir2.size() > programPath.size());
    CPPUNIT_ASSERT(tmpDir2.substr(0, programPath.size()) == programPath);
    CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir2.c_str()));
  }
Example #24
0
// protected
void 
FileInputStreamTestCase::read (void)
{
	FileInputStream fin (TEST_FILE_NAME);
	
	int byte = fin.read ();
	CPPUNIT_ASSERT ( (char)byte == 'T');
	byte = fin.read ();
	CPPUNIT_ASSERT ((char)byte == 'e');
	
	unsigned char readBuf[11];
	CPPUNIT_ASSERT (fin.read(readBuf, 10) == 10);
	readBuf[10] = 0;
	CPPUNIT_ASSERT (strncmp ((char*) readBuf, "st line 1\r", 10) == 0);
	
	CPPUNIT_ASSERT (fin.read(readBuf, 4) == 4);
	CPPUNIT_ASSERT (strncmp ((char*) readBuf, "\nTes", 4) == 0);
	
	CPPUNIT_ASSERT_THROW (fin.read (0, 0), Exception);
	
	CPPUNIT_ASSERT ((char)fin.read () == 't');
	CPPUNIT_ASSERT (fin.read(readBuf, 0) == 0);
	CPPUNIT_ASSERT (fin.read(readBuf, 10) == 10);
	CPPUNIT_ASSERT (fin.read(readBuf, 4) == 4);
	CPPUNIT_ASSERT (fin.read(readBuf, 10) == 6);
	CPPUNIT_ASSERT (fin.read(readBuf, 4) == -1);
	CPPUNIT_ASSERT (fin.read() == -1);

	fin.close ();
}
Example #25
0
    void TestAppend(void)
    {
        m_empty->Append(L"some/append\\path/");
        m_directory->Append(L"some/append\\path/file");
        m_path->Append(L".new.ext");
        // Check correct parsing of folder and file name for empy paths,
        // folder only paths and paths with bor filename and folders.
#if defined(WIN32)
        CPPUNIT_ASSERT(m_empty->GetDirectory() == L"some\\append\\path\\");
        CPPUNIT_ASSERT(m_empty->GetFilename() == L"");
        CPPUNIT_ASSERT(m_directory->GetDirectory() == L"dir\\some\\append\\path\\");
        CPPUNIT_ASSERT(m_directory->GetFilename() == L"file");
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"some\\path\\");
        CPPUNIT_ASSERT(m_path->GetFilename() == L"file.ext.new.ext");
#else
        CPPUNIT_ASSERT(m_empty->GetDirectory() == L"some/append/path/");
        CPPUNIT_ASSERT(m_empty->GetFilename() == L"");
        CPPUNIT_ASSERT(m_directory->GetDirectory() == L"dir/some/append/path/");
        CPPUNIT_ASSERT(m_directory->GetFilename() == L"file");
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"some/path/");
        CPPUNIT_ASSERT(m_path->GetFilename() == L"file.ext.new.ext");
#endif

        // Check for correct exception when folder separators in append string and path 
        // already has a file name.
        SCXUNIT_RESET_ASSERTION();
        CPPUNIT_ASSERT_THROW(m_path->Append(L"path/with\\file"), SCXCoreLib::SCXInvalidArgumentException);
        SCXUNIT_ASSERTIONS_FAILED(2); // both in append function and in SCXInvalidArgumentException constructor

        m_empty->Append(L"/double/");
        // Check that any starting folder separators are removed if appending to existing folder.
#if defined(WIN32)
        CPPUNIT_ASSERT(m_empty->GetDirectory().find(L"\\\\") == std::wstring::npos);
#else
        CPPUNIT_ASSERT(m_empty->GetDirectory().find(L"//") == std::wstring::npos);
#endif
    }
void TestSpinNetwork::test_operator_access()
{
  (*testnetwork_dynamic)[0] = IsingSpin(-1);
  CPPUNIT_ASSERT((*testnetwork_dynamic)[0] == IsingSpin(-1));
}
Example #27
0
void ListsTestCase::wxStdListTest()
{
    wxListInt list1;
    wxListInt::iterator it, en;
    wxListInt::reverse_iterator rit, ren;
    int i;
    for ( i = 0; i < 5; ++i )
        list1.push_back(i + &i);

    for ( it = list1.begin(), en = list1.end(), i = 0;
          it != en; ++it, ++i )
    {
        CPPUNIT_ASSERT( *it == i + &i );
    }

    for ( rit = list1.rbegin(), ren = list1.rend(), i = 4;
          rit != ren; ++rit, --i )
    {
        CPPUNIT_ASSERT( *rit == i + &i );
    }

    CPPUNIT_ASSERT( *list1.rbegin() == *--list1.end() &&
                    *list1.begin() == *--list1.rend() );
    CPPUNIT_ASSERT( *list1.begin() == *--++list1.begin() &&
                    *list1.rbegin() == *--++list1.rbegin() );

    CPPUNIT_ASSERT( list1.front() == &i && list1.back() == &i + 4 );

    list1.erase(list1.begin());
    list1.erase(--list1.end());

    for ( it = list1.begin(), en = list1.end(), i = 1;
          it != en; ++it, ++i )
    {
        CPPUNIT_ASSERT( *it == i + &i );
    }

    list1.clear();
    CPPUNIT_ASSERT( list1.empty() );

    it = list1.insert(list1.end(), (int *)1);
    CPPUNIT_ASSERT_EQUAL( (int *)1, *it );
    CPPUNIT_ASSERT( it == list1.begin() );
    CPPUNIT_ASSERT_EQUAL( (int *)1, list1.front() );

    it = list1.insert(list1.end(), (int *)2);
    CPPUNIT_ASSERT_EQUAL( (int *)2, *it );
    CPPUNIT_ASSERT( ++it == list1.end() );
    CPPUNIT_ASSERT_EQUAL( (int *)2, list1.back() );

    it = list1.begin();
    wxListInt::iterator it2 = list1.insert(++it, (int *)3);
    CPPUNIT_ASSERT_EQUAL( (int *)3, *it2 );

    it = list1.begin();
    it = list1.erase(++it, list1.end());
    CPPUNIT_ASSERT_EQUAL( 1, list1.size() );
    CPPUNIT_ASSERT( it == list1.end() );

    wxListInt list2;
    list2.push_back((int *)3);
    list2.push_back((int *)4);
    list1.insert(list1.begin(), list2.begin(), list2.end());
    CPPUNIT_ASSERT_EQUAL( 3, list1.size() );
    CPPUNIT_ASSERT_EQUAL( (int *)3, list1.front() );

    list1.insert(list1.end(), list2.begin(), list2.end());
    CPPUNIT_ASSERT_EQUAL( 5, list1.size() );
    CPPUNIT_ASSERT_EQUAL( (int *)4, list1.back() );
}
void TestSpinNetwork::test_all_steps()
{
  // Calculate all steps
  std::vector<SpinNetworkStep<IsingSpin, std::vector<IsingSpin*> > > all_steps_dynamic = 
    testnetwork_dynamic->all_steps();
  std::vector<SpinNetworkStep<IsingSpin, std::array<IsingSpin*, 2> > > all_steps_static = 
    testnetwork_static->all_steps();
  
  // Check the size of all steps
  CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(all_steps_dynamic.size()));
  CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(all_steps_static.size()));

  // Check that the old and the new spin are correct
  CPPUNIT_ASSERT(all_steps_dynamic[0].get_old_spin() == IsingSpin(1));
  CPPUNIT_ASSERT(all_steps_dynamic[1].get_old_spin() == IsingSpin(1));
  CPPUNIT_ASSERT(all_steps_dynamic[2].get_old_spin() == IsingSpin(1));
  CPPUNIT_ASSERT(all_steps_dynamic[0].get_new_spin() == IsingSpin(-1));
  CPPUNIT_ASSERT(all_steps_dynamic[1].get_new_spin() == IsingSpin(-1));
  CPPUNIT_ASSERT(all_steps_dynamic[2].get_new_spin() == IsingSpin(-1));
  CPPUNIT_ASSERT(all_steps_static[0].get_old_spin() == IsingSpin(1));
  CPPUNIT_ASSERT(all_steps_static[1].get_old_spin() == IsingSpin(1));
  CPPUNIT_ASSERT(all_steps_static[2].get_old_spin() == IsingSpin(1));
  CPPUNIT_ASSERT(all_steps_static[0].get_new_spin() == IsingSpin(-1));
  CPPUNIT_ASSERT(all_steps_static[1].get_new_spin() == IsingSpin(-1));
  CPPUNIT_ASSERT(all_steps_static[2].get_new_spin() == IsingSpin(-1));

  // Define boolean variables indicating whether an index was tried to flip
  bool dynamic_index_0_found = false; bool static_index_0_found = false;
  bool dynamic_index_1_found = false; bool static_index_1_found = false;
  bool dynamic_index_2_found = false; bool static_index_2_found = false;
  if (all_steps_dynamic[0].get_flip_index() == 0) dynamic_index_0_found = true;
  if (all_steps_dynamic[0].get_flip_index() == 1) dynamic_index_1_found = true;
  if (all_steps_dynamic[0].get_flip_index() == 2) dynamic_index_2_found = true;
  if (all_steps_dynamic[1].get_flip_index() == 0) dynamic_index_0_found = true;
  if (all_steps_dynamic[1].get_flip_index() == 1) dynamic_index_1_found = true;
  if (all_steps_dynamic[1].get_flip_index() == 2) dynamic_index_2_found = true;
  if (all_steps_dynamic[2].get_flip_index() == 0) dynamic_index_0_found = true;
  if (all_steps_dynamic[2].get_flip_index() == 1) dynamic_index_1_found = true;
  if (all_steps_dynamic[2].get_flip_index() == 2) dynamic_index_2_found = true;
  if (all_steps_static[0].get_flip_index() == 0) static_index_0_found = true;
  if (all_steps_static[0].get_flip_index() == 1) static_index_1_found = true;
  if (all_steps_static[0].get_flip_index() == 2) static_index_2_found = true;
  if (all_steps_static[1].get_flip_index() == 0) static_index_0_found = true;
  if (all_steps_static[1].get_flip_index() == 1) static_index_1_found = true;
  if (all_steps_static[1].get_flip_index() == 2) static_index_2_found = true;
  if (all_steps_static[2].get_flip_index() == 0) static_index_0_found = true;
  if (all_steps_static[2].get_flip_index() == 1) static_index_1_found = true;
  if (all_steps_static[2].get_flip_index() == 2) static_index_2_found = true;
  // Check wether all indices were found
  CPPUNIT_ASSERT(dynamic_index_0_found);
  CPPUNIT_ASSERT(dynamic_index_1_found);
  CPPUNIT_ASSERT(dynamic_index_2_found);
  CPPUNIT_ASSERT(static_index_0_found);
  CPPUNIT_ASSERT(static_index_1_found);
  CPPUNIT_ASSERT(static_index_2_found);
}
void CNLog2RatioEngineTest::checkOptionsTest()
{
	Verbose::out(1, "****CNLog2RatioEngineTest::checkOptionsTest****");
	
	CNLog2RatioEngine m_objCNLog2RatioEngine1;
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine1.isOptDefined("set-analysis-name"));
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine1.getOpt("set-analysis-name")=="");
	//Must specify a reference-file.
	NEGATIVE_TEST(m_objCNLog2RatioEngine1.checkOptions(),Except);
    
	//Must specify a expr-summary-file
    CNLog2RatioEngine m_objCNLog2RatioEngine2a;
    m_objCNLog2RatioEngine2a.setOpt("reference-file",INPUT + "/CNReference.a5");
	NEGATIVE_TEST(m_objCNLog2RatioEngine2a.checkOptions(),Except);

	//Must specify a genotype-calls-file
    CNLog2RatioEngine m_objCNLog2RatioEngine2;
	m_objCNLog2RatioEngine2.setOpt("reference-file",INPUT + "/CNReference.a5");
    m_objCNLog2RatioEngine2.setOpt("expr-summary-file",INPUT + "/Test.plier.summary.txt");
	NEGATIVE_TEST(m_objCNLog2RatioEngine2.checkOptions(), Except);

    //Must specify a genotype-confidences-file
    CNLog2RatioEngine m_objCNLog2RatioEngine3;
	m_objCNLog2RatioEngine3.setOpt("reference-file",INPUT + "/CNReference.a5");
	m_objCNLog2RatioEngine3.setOpt("expr-summary-file",INPUT + "/Test.plier.summary.txt");
    m_objCNLog2RatioEngine3.setOpt("genotype-calls-file",INPUT + "/Test.report1.txt");
	NEGATIVE_TEST(m_objCNLog2RatioEngine3.checkOptions(), Except);

	//Must specify a genoptype-report-file
    CNLog2RatioEngine m_objCNLog2RatioEngine4;
	m_objCNLog2RatioEngine4.setOpt("reference-file",INPUT + "/CNReference.a5");
	m_objCNLog2RatioEngine4.setOpt("expr-summary-file",INPUT + "/Test.plier.summary.txt");
    m_objCNLog2RatioEngine4.setOpt("genotype-calls-file",INPUT + "/Test.report1.txt");
	m_objCNLog2RatioEngine4.setOpt("genotype-confidences-file",INPUT + "/Test.report2.txt");
	NEGATIVE_TEST(m_objCNLog2RatioEngine4.checkOptions(), Except);

	//Must specify a netaffx annotation-file.
    CNLog2RatioEngine m_objCNLog2RatioEngine5;
	m_objCNLog2RatioEngine5.setOpt("reference-file",INPUT + "/CNReference.a5");
	m_objCNLog2RatioEngine5.setOpt("expr-summary-file",INPUT + "/Test.plier.summary.txt");
    m_objCNLog2RatioEngine5.setOpt("genotype-calls-file",INPUT + "/Test.report1.txt");
	m_objCNLog2RatioEngine5.setOpt("genotype-confidences-file",INPUT + "/Test.report2.txt");
	m_objCNLog2RatioEngine5.setOpt("genotype-report-file",INPUT + "/Test.report.txt");
	NEGATIVE_TEST(m_objCNLog2RatioEngine5.checkOptions(), Except);

	
	CNLog2RatioEngine m_objCNLog2RatioEngine6;
	m_objCNLog2RatioEngine6.setOpt("reference-file",INPUT + "/CNReference.a5");
	m_objCNLog2RatioEngine6.setOpt("expr-summary-file",INPUT + "/Test.plier.summary.txt");
    m_objCNLog2RatioEngine6.setOpt("genotype-calls-file",INPUT + "/Test.report1.txt");
	m_objCNLog2RatioEngine6.setOpt("genotype-confidences-file",INPUT + "/Test.report2.txt");
	m_objCNLog2RatioEngine6.setOpt("genotype-report-file",INPUT + "Test.report.txt");
	m_objCNLog2RatioEngine6.setOpt("reference-file",INPUT + "/CNReference.a5");
	m_objCNLog2RatioEngine6.setOpt("annotation-file",INPUT + "/GenomeWideSNP_test_6.na23.annot_small.csv");
	m_objCNLog2RatioEngine6.defineOption("", "cn-calibrate-parameters", PgOpt::STRING_OPT,
                    "SmoothSignal calibration parameters", "");
	POSITIVE_TEST(m_objCNLog2RatioEngine6.setOpt("log2ratio-text-output","true"));
	POSITIVE_TEST(m_objCNLog2RatioEngine6.checkOptions());
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine6.getOptBool("log2ratio-hdf5-output")==true);
	CPPUNIT_ASSERT(m_objCNLog2RatioEngine6.getOptBool("log2ratio-text-output")==false);	
}
Example #30
0
void UnitTestOutputLog::testUnit()
{
  // Make cout and cerr available as log stream targets.
  stk::register_log_ostream(std::cout, "cout");
  stk::register_log_ostream(std::cerr, "cerr");

  // Test registration, binding, rebinding and unregistration
  {
    std::ostringstream log1;
    std::ostringstream log2;
    
    std::ostream out(std::cout.rdbuf());

    stk::register_ostream(out, "out");

    CPPUNIT_ASSERT(stk::is_registered_ostream("out"));
    
    stk::register_log_ostream(log1, "log1");
    stk::register_log_ostream(log2, "log2");

    stk::bind_output_streams("out>log1");

    out << "stk::bind_output_streams(\"out>log1\");" << std::endl;

    stk::bind_output_streams("out>+log2");
    out << "stk::bind_output_streams(\"out>+log2\");" << std::endl;
    
    stk::bind_output_streams("out>-log1");
    out << "stk::bind_output_streams(\"out>-log1\");" << std::endl;

    stk::bind_output_streams("out>-log2");
    out << "stk::bind_output_streams(\"out>-log2\");" << std::endl;

    std::ostringstream log1_result;
    log1_result << "stk::bind_output_streams(\"out>log1\");" << std::endl
                << "stk::bind_output_streams(\"out>+log2\");" << std::endl;
    
    std::ostringstream log2_result;
    log2_result << "stk::bind_output_streams(\"out>+log2\");" << std::endl
                << "stk::bind_output_streams(\"out>-log1\");" << std::endl;
    
    CPPUNIT_ASSERT_EQUAL(log1_result.str(), log1.str());
    CPPUNIT_ASSERT_EQUAL(log2_result.str(), log2.str());

    stk::unregister_log_ostream(log1);
    stk::unregister_log_ostream(log2);
    stk::unregister_ostream(out);

    CPPUNIT_ASSERT_EQUAL(out.rdbuf(), std::cout.rdbuf());
  }

  // Test logging to a file
  {
    std::ostream out(std::cout.rdbuf());

    stk::register_ostream(out, "out");

    stk::bind_output_streams("log=\"logfile\" out>log");

    CPPUNIT_ASSERT_EQUAL(std::string("logfile"), stk::get_log_path("log")); 
    
    out << "This is a test" << std::endl;

    stk::bind_output_streams("log=\"\"");
    
    stk::unregister_ostream(out);

    std::ostringstream log_result;
    log_result << "This is a test";
    
    std::ifstream log_stream("logfile");
    std::string log_string;
    getline(log_stream, log_string);
    CPPUNIT_ASSERT_EQUAL(log_result.str(), log_string);
  }

  // Test results of unregistration of an output stream bound as a log stream
  {
    std::ostringstream default_log;
    std::ostream out(default_log.rdbuf());
    std::ostream pout(std::cout.rdbuf());

    stk::register_ostream(out, "out");
    stk::register_ostream(pout, "pout");

    //  Constructing the log streams after the registered output stream is not exception safe.
    std::ostringstream log;
    stk::register_log_ostream(log, "log");

    // As a result, this try catch block must be represent to ensure the that unregistration
    // happens correctly.
    try {  
      stk::bind_output_streams("out>pout pout>log");

      out << "This is to out" << std::endl;
      pout << "This is to pout" << std::endl;

      std::ostringstream log_result;
      log_result << "This is to out" << std::endl
                 << "This is to pout" << std::endl;
    
      CPPUNIT_ASSERT_EQUAL(log_result.str(), log.str());

      throw std::exception();
    }
    catch (...) {
    }

    stk::unregister_log_ostream(log);
    stk::unregister_ostream(pout);
    stk::unregister_ostream(out);

    out << "This is to out" << std::endl;

    std::ostringstream log_result;
    log_result << "This is to out" << std::endl;
    CPPUNIT_ASSERT_EQUAL(log_result.str(), default_log.str());
  }

  // Test exception of registration with existing name
  {
    std::ostringstream log1;
    std::ostringstream log2;
    
    std::ostream out(std::cout.rdbuf());
    std::ostream pout(std::cout.rdbuf());

    stk::register_ostream(out, "out");
    CPPUNIT_ASSERT_THROW(stk::register_ostream(pout, "out"), std::runtime_error);

    CPPUNIT_ASSERT_EQUAL(&out, stk::get_ostream_ostream("out"));

    stk::register_log_ostream(log1, "log");
    
    CPPUNIT_ASSERT_THROW(stk::register_log_ostream(log2, "log"), std::runtime_error);

    CPPUNIT_ASSERT_THROW(stk::bind_output_streams("badout>log"), std::runtime_error);
    
    CPPUNIT_ASSERT_THROW(stk::bind_output_streams("out>badlog"), std::runtime_error);

    stk::unregister_log_ostream(log1);
    stk::unregister_ostream(out);
  }
}