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_size_tests.c

Go to the documentation of this file.
00001 /** @file file_size.c
00002  * Example of using the GAT to get the size of a file.
00003  * 
00004  * Uses the GAT to get the size of a file at a given URI is readable.
00005  * 
00006  * @date Mon Oct 6 2003
00007  * 
00008  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/file_size_tests.c,v 1.7 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_size_tests.c,v 1.7 2004/04/20 17:04:59 hartmutkaiser Exp $";
00020 
00021 
00022 /* System Header Files */
00023 
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 
00027 
00028 /* GAT Header Files */
00029 
00030 #include <GAT.h>
00031 #include <GATTestUtils.h>
00032 
00033 
00034 /* File scope variables */
00035 
00036 static GATStaticMetric metric_data = {
00037   /* fileops.file_copied event */
00038   "fileops.file_size",            /* name */
00039   GATMeasurementType_Continuous,  /* type */
00040   GATType_GATuint32,              /* data type */
00041   "Bytes",                        /* unit */
00042   0,                              /* parameter count */
00043   0                               /* parameters */
00044 };
00045 
00046 
00047 /* External functions */
00048 
00049 int main (void)
00050 {
00051   GATResult      retcode = GAT_FAIL;
00052   GATContext     context = NULL;
00053   GATLocation    target  = NULL;
00054   GATFile        file    = NULL;
00055   GATMetric      metric  = NULL;
00056   GATMetricEvent event   = NULL;
00057   GATuint32      cookie  = 0;
00058   const char*    src     = NULL;
00059 
00060   GATType   type           = GATType_NoType;
00061   GATuint32 direct_length  = 0;
00062   GATuint32 polling_length = 0;
00063 
00064   GAT_TEST_INIT  (-1);
00065   GAT_TEST_SUITE ("File")
00066 
00067   context = GATContext_Create ();
00068   GAT_TEST(NULL != context);
00069   
00070   /* the following test makes sure, that there were no errors during the 
00071      creation of the GATContext object */
00072   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00073 
00074   GAT_TEST_START ("File Size Tests")
00075 
00076   src = GATTest_CreateTempFile ("gat_src");
00077   GAT_TEST_TRACE(NULL != src, context);
00078 
00079   target = GATLocation_Create (src);
00080   GAT_TEST_TRACE(NULL != target, context);
00081 
00082   file = GATFile_Create(context, target, 0);
00083   GAT_TEST_TRACE(NULL != file, context);
00084   
00085   /* install the event handler */
00086   retcode = GATMetric_CreateMetric(&metric_data, &metric);
00087   GAT_TEST_TRACE(GAT_SUCCEEDED(retcode), context);
00088   GAT_TEST_TRACE(NULL != metric, context);
00089   
00090   retcode = GATMonitorable_RegisterPolling (GATFile_ToGATObject(file), 
00091                                             metric, &event, &cookie);
00092   GAT_TEST_TRACE(GAT_SUCCEEDED(retcode), context);
00093   GAT_TEST_TRACE(0 != cookie, context);
00094   
00095   /* get the file size directly */
00096   retcode = GATFile_GetLength (file, (unsigned long *)&direct_length);
00097   GAT_TEST_TRACE(GAT_SUCCEEDED(retcode), context);
00098 
00099   /* get the file size through polling */
00100   type = GATMetricEvent_GetValueType (event);  /* ensure expected type */
00101   GAT_TEST_TRACE(GATType_GATuint32 == type, context); 
00102 
00103   retcode = GATMetricEvent_GetValue (event, &polling_length, 
00104                                      sizeof (polling_length));
00105   GAT_TEST_TRACE(GAT_SUCCEEDED(retcode), context);
00106   GAT_TEST_TRACE(direct_length == polling_length, context);
00107 
00108   retcode = GATMonitorable_RemoveRegisteredMetric (GATFile_ToGATObject (file), 
00109                                                    metric, cookie);
00110   GAT_TEST_TRACE(GAT_SUCCEEDED(retcode), context);
00111     
00112   GAT_TEST_STOP ();
00113   
00114   GATMetric_Destroy      (&metric);
00115   GATMetricEvent_Destroy (&event);
00116   GATFile_Destroy        (&file);
00117   GATLocation_Destroy    (&target);
00118   GATContext_Destroy     (&context);
00119 
00120   GAT_TEST_FINISH();
00121 
00122   return (retcode);
00123 }
00124