void PathUtilsSuite_TestFindFile( PathUtilsSuiteData* data ) {
   char*       searchPaths = NULL;
   char        fullPath[1024];
   const char* subDir = "./testSubDir";
   const char* subDirFilename = "./testSubDir/subDirTest.xml";
   const char* currDirFilename = "./currDirTest.xml";


   Stg_asprintf( &searchPaths, ".:%s:/does/not/exist", subDir );
   /* Create necessary test files/dirs */
   if (data->rank==0) {
      FILE* subDirFile = NULL;
      FILE* currDirFile = NULL;

      currDirFile = fopen( currDirFilename, "w" );
      fputs( "test.\n", currDirFile );
      fclose( currDirFile );
      mkdir( subDir, 0755 );
      subDirFile = fopen( subDirFilename, "w" );
      fputs( "test.\n", subDirFile );
      fclose( subDirFile );
   }
   MPI_Barrier(MPI_COMM_WORLD);

   /* try and open some files using the search path */
   /* Only do this using proc 0 - for why, see warning in Doxygen comment for the function. */
   if (data->rank==0) {
      /* This first test is to make sure it can handle files preceded with ./ */
      FindFile( fullPath, currDirFilename, searchPaths );
      pcu_check_streq( fullPath, currDirFilename );

      FindFile( fullPath, "currDirTest.xml", searchPaths );
      pcu_check_streq( fullPath, currDirFilename );
      
      FindFile( fullPath, "subDirTest.xml", searchPaths );
      pcu_check_streq( fullPath, subDirFilename );
      
      FindFile( fullPath, "nofile.man", searchPaths );
      pcu_check_streq( fullPath, "" );
      
      FindFile( fullPath, "/Users/luke/Projects/StGermain/env_vars", searchPaths );
      pcu_check_streq( fullPath, "" );
   }

   if (data->rank==0) {
      remove( currDirFilename );
      remove( subDirFilename );
      rmdir( subDir );
   }
}
void DictionarySuite_TestCreateValues( DictionarySuiteData* data ) {
   Dictionary_Entry_Value*   dev;

   /* Don't use the pre-created test values. Want to do a very fundamental test here */
   dev = Dictionary_Entry_Value_FromString( "hello" );
   pcu_check_true( Dictionary_Entry_Value_Type_String == dev->type );
   pcu_check_streq( "hello", dev->as.typeString );
   Dictionary_Entry_Value_Delete( dev );
   dev = Dictionary_Entry_Value_FromDouble( 45.567 );
   pcu_check_true( Dictionary_Entry_Value_Type_Double == dev->type );
   pcu_check_true( 45.567 == dev->as.typeDouble );
   Dictionary_Entry_Value_Delete( dev );
   dev = Dictionary_Entry_Value_FromUnsignedInt( 5 );
   pcu_check_true( Dictionary_Entry_Value_Type_UnsignedInt == dev->type );
   pcu_check_true( 5 == dev->as.typeUnsignedInt );
   Dictionary_Entry_Value_Delete( dev );
   dev = Dictionary_Entry_Value_FromInt( -5 );
   pcu_check_true( Dictionary_Entry_Value_Type_Int == dev->type );
   pcu_check_true( -5 == dev->as.typeInt );
   Dictionary_Entry_Value_Delete( dev );
   dev = Dictionary_Entry_Value_FromUnsignedLong( 52342423 );
   pcu_check_true( Dictionary_Entry_Value_Type_UnsignedLong == dev->type );
   pcu_check_true( 52342423 == dev->as.typeUnsignedLong );
   Dictionary_Entry_Value_Delete( dev );
   dev = Dictionary_Entry_Value_FromBool( True );
   pcu_check_true( Dictionary_Entry_Value_Type_Bool == dev->type );
   pcu_check_true( True == dev->as.typeBool );
   Dictionary_Entry_Value_Delete( dev );

   /* Since we know the DEV Struct is basically a Dictionary, won't test that one
    *  until after we've tested Dictionary_Add works */   
}
void ProgressSuite_TestSetPrefix( ProgressSuiteData* data ) {
   Progress_SetPrefix( data->prog, NULL );
   pcu_check_true( data->prog->preStr == NULL );
   Progress_SetPrefix( data->prog, "foo" );
   pcu_check_streq( data->prog->preStr, "foo" );
   Progress_SetPrefix( data->prog, NULL );
   pcu_check_true( data->prog->preStr == NULL );
}
void ProgressSuite_TestSetTitle( ProgressSuiteData* data ) {
   Progress_SetTitle( data->prog, NULL );
   pcu_check_true( data->prog->title == NULL );
   Progress_SetTitle( data->prog, "foo" );
   pcu_check_streq( data->prog->title, "foo" );
   Progress_SetTitle( data->prog, NULL );
   pcu_check_true( data->prog->title == NULL );
}
void ProgressSuite_TestSetRange( ProgressSuiteData* data ) {
   Progress_SetRange( data->prog, 5, 10 );
   pcu_check_true( data->prog->start == 5 );
   pcu_check_true( data->prog->end == 10 );
   Progress_SetPrefix( data->prog, "foo" );
   pcu_check_streq( data->prog->preStr, "foo" );
   Progress_SetPrefix( data->prog, NULL );
   pcu_check_true( data->prog->preStr == NULL );
}
void DictionarySuite_TestShortcuts( DictionarySuiteData* data ) {

   DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD );

   /* Testing GetString_WithDefault. If an entry with that key already exists, then
    *  the value of the existing key should be returned, and the default passed in
    *  ignored. However if the given key _doesn't_ exist, the default should be 
    *  returned, and a new entry with the given key added to the dict. */
   pcu_check_streq( data->testDD->testString, Dictionary_GetString_WithDefault( data->dict, "test_cstring", "heya" ) );
   pcu_check_streq( "heya", Dictionary_GetString_WithDefault( data->dict, "test_cstring2", "heya" ) );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_cstring2" )  );
	data->testDD->testDouble = Dictionary_GetDouble_WithDefault( data->dict, (Dictionary_Entry_Key)"test_double", 2.8 );
   pcu_check_true( data->testDD->testDouble );
   pcu_check_true( 2.8 == Dictionary_GetDouble_WithDefault( data->dict, (Dictionary_Entry_Key)"test_double2", 2.8 )  );

   /* test_placeholder refers to test_double which equals 45.567 */
   pcu_check_true( 45.567 == Dictionary_GetDouble_WithScopeDefault( data->dict, (Dictionary_Entry_Key)"test_placeholder", -1 )  );
   
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_double2" )  );
   data->testDD->testUint = Dictionary_GetUnsignedInt_WithDefault( data->dict, "test_uint", 33 );
	pcu_check_true( data->testDD->testUint );
   pcu_check_true( 33 == Dictionary_GetUnsignedInt_WithDefault( data->dict, "test_uint2", 33 ) );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_uint2" )  );
   data->testDD->testInt = Dictionary_GetInt_WithDefault( data->dict, (Dictionary_Entry_Key)"test_int", -24 );
	pcu_check_true( data->testDD->testInt );
   pcu_check_true( -24 == Dictionary_GetInt_WithDefault( data->dict, (Dictionary_Entry_Key)"test_int2", -24 )  );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_int2" )  );
   data->testDD->testUnsignedlong = Dictionary_GetUnsignedLong_WithDefault( data->dict, "test_unsignedlong", 32433 );
	pcu_check_true( data->testDD->testUnsignedlong );
   pcu_check_true( 32433 == Dictionary_GetUnsignedLong_WithDefault( data->dict, "test_unsignedlong2", 32433 ) );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_unsignedlong2" )  );
   data->testDD->testBool = Dictionary_GetBool_WithDefault( data->dict, (Dictionary_Entry_Key)"test_bool", False );
	pcu_check_true( data->testDD->testBool );
   pcu_check_true( False == Dictionary_GetBool_WithDefault( data->dict, (Dictionary_Entry_Key)"test_bool2", False )  );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_bool2" )  );

   pcu_check_streq( data->testDD->testString, Dictionary_GetString_WithPrintfDefault( data->dict, "test_cstring", "heya%s%u", "hey", 3 ) );
   pcu_check_streq( "heyahey3", Dictionary_GetString_WithPrintfDefault( data->dict, "test_cstring3", "heya%s%u", "hey", 3 ) );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_cstring3" ) );
}
void PathUtilsSuite_TestPathJoin( PathUtilsSuiteData* data ) {
   char     searchPaths[1024];
   unsigned len;
   
   PathJoin( searchPaths, 1, "." );
   len = strlen( searchPaths );
   searchPaths[len] = ':';
   
   PathJoin( &searchPaths[len + 1], 2,  ".", "data" );
   len = strlen( searchPaths );
   searchPaths[len] = ':';
   
   PathJoin( &searchPaths[len + 1], 6, "..", "..", "..", "does", "not", "exist" );
   
   pcu_check_streq( searchPaths, ".:./data:../../../does/not/exist" );
}
void SwarmOutputSuite_TestSwarmOutput( SwarmOutputSuiteData* data ) {
   int procToWatch = data->nProcs > 1 ? 1 : 0;

   if( data->rank == procToWatch ) {
      Dictionary*                dictionary;
      Dictionary*                componentDict;
      Stg_ComponentFactory*      cf;
      DomainContext*             context;
      char                       input_file[PCU_PATH_MAX];
      Swarm*                     swarm;
      SwarmOutput*               swarmOutput;
      SpaceFillerParticleLayout* particleLayout;

      pcu_filename_input( "testSwarmOutput.xml", input_file );
      cf = stgMainInitFromXML( input_file, data->comm, NULL );
      context = (DomainContext*) LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
      dictionary = context->dictionary;

      Journal_ReadFromDictionary( dictionary );
      stgMainBuildAndInitialise( cf  );

      ContextEP_Append( context, AbstractContext_EP_Dt, SwarmOutputSuite_Dt );
      ContextEP_Append( context, AbstractContext_EP_Step, SwarmOutputSuite_MoveParticles );

      componentDict = Dictionary_GetDictionary( dictionary, "components" );
      assert( componentDict );

      AbstractContext_Dump( context );
      Stg_Component_Execute( context, 0, False );

      particleLayout = (SpaceFillerParticleLayout*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"particleLayout" );
      swarmOutput = (SwarmOutput* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarmOutput" );
      swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm" );

      pcu_check_true( particleLayout->isConstructed && particleLayout->isBuilt && particleLayout->isInitialised );
      pcu_check_true( swarmOutput->isConstructed && swarmOutput->isBuilt && swarmOutput->isInitialised );
      pcu_check_true( swarm->isConstructed && swarm->isBuilt && swarm->isInitialised  );

      pcu_check_streq( swarm->name, swarmOutput->swarm->name );

      stgMainDestroy( cf );
   }
}
void FieldVariableRegisterSuite_TestGetByIndex( FieldVariableRegisterSuiteData* data ) {
   int                     procToWatch;
   FieldVariable_Register* fV_Register;
   FieldVariable*          testFVs[] = { NULL, NULL, NULL };
   Name                    fvNames[] = { "testFV1", "testFV2", "testFV3" };
   Index                   ii;
   Index                   fV_Index;

   procToWatch = data->nProcs >=2 ? 1 : 0;

   if( data->rank == procToWatch ) {
      fV_Register = FieldVariable_Register_New();

      for( ii=0; ii < 3; ii++ ) {
         testFVs[ii] = FieldVariable_New(
            fvNames[ii],
            NULL,
            0,
            3,
            False,
            data->comm,
            fV_Register );
         testFVs[ii]->_interpolateValueAt = FieldVariableRegisterSuite_dummyInterpolateValueAt;
         testFVs[ii]->_getMinGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMinGlobalValue;
         testFVs[ii]->_getMaxGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMaxGlobalValue;
         testFVs[ii]->_getMinAndMaxLocalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxLocalCoords;
         testFVs[ii]->_getMinAndMaxGlobalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxGlobalCoords;

      }
      for( ii=0; ii < 3; ii++ ) {
         fV_Index = FieldVariable_Register_GetIndex( fV_Register, fvNames[ii] );
         pcu_check_true( fV_Index == ii );
         pcu_check_streq( (FieldVariable_Register_GetByIndex( fV_Register, fV_Index ) )->name, fvNames[ii] );
      }
      Stg_Class_Delete(fV_Register);
   }
}