GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

file_move_tests.c

Go to the documentation of this file.
00001 /** @file file_move.c
00002  * Example of using the GAT to move a file.
00003  * 
00004  * Uses the GAT to move a file given two URIs on the command line.
00005  * 
00006  * @date Mon Oct 6 2003
00007  * 
00008  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/file_move_tests.c,v 1.9 2004/04/20 17:04:59 hartmutkaiser Exp $
00009  *
00010  *  Copyright (C) Hartmut Kaiser
00011  *  This file is part of the GAT Engine.
00012  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00013  *
00014  *  Use, modification and distribution is subject to the Gridlab Software
00015  *  License. (See accompanying file GLlicense.txt or copy at
00016  *  http://www.gridlab.org/GLlicense.txt)
00017  */
00018 
00019 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/file_move_tests.c,v 1.9 2004/04/20 17:04:59 hartmutkaiser Exp $";
00020 
00021 /* System Header Files */
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 /* GAT Header Files */
00028 
00029 #include <GAT.h>
00030 #include <GATTestUtils.h>
00031 
00032 /* Macros */
00033 
00034 /* Structures, unions and enums */
00035 
00036 /* Static function prototypes */
00037 static GATResult 
00038   Listener_FileMoved(void *data, GATMetricEvent event);
00039 
00040 /* File scope variables */
00041 static GATStaticMetric metric_data = {
00042   /* fileops.file_copied event */
00043   "fileops.file_moved",           /* name */
00044   GATMeasurementType_EventLike,   /* type */
00045   GATType_String,                 /* data type */
00046   "",                             /* unit */
00047   0,                              /* parameter count */
00048   0                               /* parameters */
00049 };
00050 
00051 /* External functions */
00052 
00053 int main (void)
00054 {
00055   GATResult   retcode = GAT_SUCCESS;
00056   GATContext  context = NULL;
00057   GATLocation source  = NULL;
00058   GATLocation target  = NULL;
00059   GATMetric   metric  = NULL;
00060   GATFile     file    = NULL;
00061   GATuint32   cookie  = 0;
00062   const char* src     = NULL;
00063   const char* dst     = NULL;
00064 
00065   GAT_TEST_INIT  (-1);
00066   GAT_TEST_SUITE ("File")
00067 
00068   context = GATContext_Create ();
00069   GAT_TEST (NULL != context);
00070   
00071   /* the following test makes sure, that there were no errors during the 
00072      creation of the GATContext object */
00073   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00074 
00075   GAT_TEST_START ("File Move Test")
00076 
00077   src = GATTest_CreateTempFile ("gat_src");
00078   GAT_TEST_TRACE (NULL != NULL != src, context);
00079 
00080   source = GATLocation_Create (src);
00081   GAT_TEST_TRACE (source, context);
00082 
00083   dst = GATTest_GetTempFileName ("gat_dst");
00084   GAT_TEST_TRACE (NULL != src, context);
00085 
00086   target = GATLocation_Create (dst);
00087   GAT_TEST_TRACE (NULL != target, context);
00088   
00089   file = GATFile_Create(context, source, 0);
00090   GAT_TEST_TRACE (NULL != file, context);
00091   
00092   /* install the event handler */
00093   retcode = GATMetric_CreateMetric(&metric_data, &metric);
00094   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00095   GAT_TEST_TRACE (NULL != metric, context);
00096   
00097   retcode = GATMonitorable_AddMetricListener (GATFile_ToGATObject(file), 
00098                                               Listener_FileMoved, 
00099                                               (void *)src, metric, &cookie);
00100   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00101   GAT_TEST_TRACE (0 != cookie, context);
00102 
00103   retcode = GATFile_Move(file, target, GATFileMode_Overwrite);
00104   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00105           
00106   retcode = GATMonitorable_RemoveRegisteredMetric (GATFile_ToGATObject (file), 
00107                                                    metric, cookie);
00108   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00109     
00110   GATFile_Destroy     (&file);
00111   GATMetric_Destroy   (&metric);
00112   GATLocation_Destroy (&source);
00113   GATLocation_Destroy (&target);
00114   GATContext_Destroy  (&context);
00115 
00116   GAT_TEST_STOP ();
00117   GAT_TEST_FINISH();
00118 
00119   return (retcode);
00120 }
00121 
00122 /* Local functions */
00123 
00124 static GATResult 
00125 Listener_FileMoved (void *data, GATMetricEvent event)
00126 {
00127   char    name[1024] = "";
00128   int     retval     = GAT_FAIL;
00129   GATType type       = GATType_NoType;
00130 
00131   GAT_TEST_START ("Listener_FileMoved");
00132 
00133   type = GATMetricEvent_GetValueType (event);
00134   GAT_TEST (type == GATType_String);
00135 
00136   retval = GATMetricEvent_GetValue (event, name, sizeof(name));
00137   GAT_TEST (GAT_SUCCESS == retval);
00138   GAT_TEST (GATType_String == type);
00139   GAT_TEST (!strcmp((char const *)data, name));
00140   
00141   GAT_TEST_STOP ();
00142 
00143   return (GAT_SUCCESS);
00144 }
00145