NMD
Functions
u6.c File Reference
#include <stdlib.h>
#include "nmd.h"
Include dependency graph for u6.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Test existence tests of components

Definition at line 5 of file u6.c.

References NMDCategoryAllocateNewComponent(), NMDCategoryTryGetComponent(), NMDCreateObject(), NMDDestroyObject(), NMDInt, NMDIntarray, NMDObjectAllocateNewCategory(), NMDObjectHasCategoryComponent(), NMDObjectTryGetCategory(), NMDReal, NMDRealarray, and NMDString.

                               {
  NMD_metadata nmd; NMDErrorCode ierr; 
  PetscFunctionBegin;
  PetscInitialize(&argc,&argv,0,0);
  ierr = NMDCreateObject(&nmd); NMD_ERR_RETURN(ierr);

  {
    NMD_metadata_category cat; NMDTruth flg;

    ierr = NMDObjectAllocateNewCategory
      (nmd,"catone",NULL); NMD_ERR_RETURN(ierr);

    ierr = NMDObjectAllocateNewCategory
      (nmd,"cat2",&cat); NMD_ERR_RETURN(ierr);

    ierr = NMDCategoryAllocateNewComponent
      (cat,"p1",NMDInt,NULL); NMD_ERR_RETURN(ierr);
    ierr = NMDCategoryAllocateNewComponent
      (cat,"ptwo",NMDReal,NULL); NMD_ERR_RETURN(ierr);
    ierr = NMDCategoryAllocateNewComponent
      (cat,"p3",NMDIntarray,NULL); NMD_ERR_RETURN(ierr);

    ierr = NMDObjectTryGetCategory
      (nmd,"catone",&cat,&flg); NMD_ERR_RETURN(ierr);
    if (!flg) NMD_ERR_REPORT("category 1 missing")

    ierr = NMDCategoryAllocateNewComponent
      (cat,"pone",NMDString,NULL); NMD_ERR_RETURN(ierr);
    ierr = NMDCategoryAllocateNewComponent
      (cat,"ptwo",NMDRealarray,NULL); NMD_ERR_RETURN(ierr);

    /* and here are the tests */
    ierr = NMDCategoryTryGetComponent
      (cat,"pone",NULL,&flg); NMD_ERR_RETURN(ierr);
    if (!flg) NMD_ERR_REPORT("Did not find pone component");
    ierr = NMDCategoryTryGetComponent
      (cat,"ptwo",NULL,&flg); NMD_ERR_RETURN(ierr);
    if (!flg) NMD_ERR_REPORT("Did not find ptwo component");
    ierr = NMDCategoryTryGetComponent
      (cat,"pthree",NULL,&flg); NMD_ERR_RETURN(ierr);
    if (flg) NMD_ERR_REPORT("Found non-existing component");
    ierr = NMDObjectHasCategoryComponent
      (nmd,"catone","p1",&flg); NMD_ERR_RETURN(ierr);
    if (flg) NMD_ERR_REPORT("found component in wrong category");
  }

  ierr = NMDDestroyObject(nmd); NMD_ERR_RETURN(ierr);
  PetscFinalize();
  PetscFunctionReturn(0);
}

Here is the call graph for this function: