GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

advertservice_add_tests.c

Go to the documentation of this file.
00001 /** @file advertservice_add_tests.c
00002  *
00003  *  Tests the GATAdvertService_Add functionality
00004  * 
00005  *  @date Fri Mar 19 2004
00006  * 
00007  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/advertservice_add_tests.c,v 1.6 2004/04/20 17:04:59 hartmutkaiser Exp $
00008  *
00009  *  Copyright (C) Hartmut Kaiser
00010  *  This file is part of the GAT Engine.
00011  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00012  *
00013  *  Use, modification and distribution is subject to the Gridlab Software
00014  *  License. (See accompanying file GLlicense.txt or copy at
00015  *  http://www.gridlab.org/GLlicense.txt)
00016  */
00017 
00018 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/advertservice_add_tests.c,v 1.6 2004/04/20 17:04:59 hartmutkaiser Exp $";
00019 
00020 /* System Header Files */
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 
00026 /* GAT Header Files */
00027 
00028 #include "GAT.h"
00029 #include "GATTestUtils.h"
00030 
00031 /* Macros */
00032 
00033 /* Structures, unions and enums */
00034 
00035 /* Static function prototypes */
00036 
00037 /* File scope variables */
00038 
00039 /* External functions */
00040 
00041 int main(int argc, const char * const argv[])
00042 {
00043   GATContext context = NULL;
00044   GATAdvertService advertservice = NULL;
00045   const char* src      = NULL;
00046   GATLocation source   = NULL;
00047   GATResult   retval   = GAT_SUCCESS;
00048   GATFile     file     = NULL;
00049   char const *pathstr  = "/AdvertServiceTests/Files/MyCheckpointFile";
00050   GATString   path     = NULL;
00051   GATTable    metadata = NULL;
00052   GATJob      self_job = NULL;
00053   GATJobID    jobid    = NULL;
00054   
00055   GAT_TEST_INIT  (-1);
00056   GAT_TEST_SUITE ("AdvertService")
00057 
00058   context = GATContext_Create();
00059   GAT_TEST(NULL != context);
00060   
00061   /* the following test makes sure, that there were no errors during the 
00062      creation of the GATContext object */
00063   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00064 
00065   GAT_TEST_START ("AdvertService Add Test");
00066 
00067   advertservice = GATAdvertService_Create(context, 0);
00068   GAT_TEST_TRACE(NULL != advertservice, context);
00069 
00070   /* create the object to advertise */  
00071   src = GATTest_CreateTempFile("gat_src");
00072   GAT_TEST_TRACE(NULL != src, context);
00073   
00074   source = GATLocation_Create(src);
00075   GAT_TEST_TRACE(NULL != source, context);
00076 
00077   file = GATFile_Create(context, source, NULL);
00078   GAT_TEST_TRACE(NULL != file, context);
00079   
00080   /* create the path, where to store the file inside the advertservice */
00081   path = GATString_Create(pathstr, (GATuint32)strlen(pathstr)+1, "ASCII");
00082   GAT_TEST_TRACE(NULL != path, context);
00083 
00084   /* construct the corresponding metadata */
00085   metadata = GATTable_Create();
00086   GAT_TEST_TRACE(NULL != metadata, context);
00087   
00088   retval = GATSelf_GetJob(context, &self_job);
00089   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00090 
00091   retval = GATJob_GetJobID(self_job, &jobid);
00092   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00093   GAT_TEST_TRACE(NULL != jobid, context);
00094   
00095   /* add the additional metadata to the table (the GAT_NAME and GAT_PATH meta
00096      data items are added automatically to the metadata set) */
00097   retval = GATTable_Add_String(metadata, "GATJobid", GATString_GetBuffer(jobid));
00098   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00099   
00100   GATJob_Destroy(&self_job);
00101   
00102   /* finally, add the file to the advertservice */
00103   retval = GATAdvertService_Add(advertservice, GATFile_ToGATObject_const(file), 
00104     metadata, path);  
00105   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00106 
00107   /* free all the allocated memory */
00108   GATTable_Destroy(&metadata);
00109   GATString_Destroy(&path);
00110   GATFile_Destroy(&file);
00111   GATLocation_Destroy (&source);
00112   GATAdvertService_Destroy(&advertservice);
00113   GATContext_Destroy(&context);
00114 
00115   GAT_TEST_STOP ();
00116   GAT_TEST_FINISH();
00117 
00118   return 0;
00119 }
00120