GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

logicalfile_serialisation_tests.c

Go to the documentation of this file.
00001 /** @file logicalfile_serialisation_tests.c
00002  * Test GATLogicalFile serialisation code.
00003  * 
00004  * @date Sat Nov 01 2003
00005  * 
00006  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/internal/logicalfile_serialisation_tests.c,v 1.21 2004/04/20 17:04:43 hartmutkaiser Exp $
00007  *
00008  *  Copyright (C) Hartmut Kaiser
00009  *  This file is part of the GAT Engine.
00010  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00011  *
00012  *  Use, modification and distribution is subject to the Gridlab Software
00013  *  License. (See accompanying file GLlicense.txt or copy at
00014  *  http://www.gridlab.org/GLlicense.txt)
00015  */
00016 
00017 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/internal/logicalfile_serialisation_tests.c,v 1.21 2004/04/20 17:04:43 hartmutkaiser Exp $";
00018 
00019 /* System Header Files */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 
00024 /* GAT Header Files */
00025 
00026 #include "GAT.h"
00027 #include "GATMemoryStream.h"
00028 
00029 #include "GATTestUtils.h"
00030 
00031 /* Macros */
00032 
00033 /* Structures, unions and enums */
00034 
00035 /* Static function prototypes */
00036 static GATResult verify_direct_serialisation  (GATContext context, GATLogicalFile file);
00037 static GATResult verify_generic_serialisation (GATContext context, GATLogicalFile file);
00038 
00039 /* File scope variables */
00040 
00041 /* External functions */
00042 
00043 int main (void)
00044 {
00045   GATResult      retcode = GAT_SUCCESS;
00046   GATContext     context = NULL;
00047   GATLocation    logfile = NULL;
00048   GATLogicalFile file    = NULL;
00049   const char* src = NULL;
00050   
00051   GAT_TEST_INIT  (-1);
00052   GAT_TEST_SUITE ("Logical File Serialization");
00053 
00054   context = GATContext_Create();
00055   GAT_TEST(NULL != context);
00056   
00057   /* the following test makes sure, that there were no errors during the 
00058      creation of the GATContext object */
00059   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00060 
00061   GAT_TEST_START ("Logical File Serialization Tests");
00062 
00063   src = GATTest_GetTempFileName ("gat_src");
00064   GAT_TEST_TRACE (NULL != src, context);
00065   
00066   logfile = GATLocation_Create (src);
00067   GAT_TEST_TRACE (NULL != logfile, context);
00068 
00069   file = GATLogicalFile_Create(context, logfile, 0, 0);
00070   GAT_TEST_TRACE (NULL != file, context);
00071 
00072   GAT_TEST_STOP ();
00073   
00074   /* test serialisation trough the direct GATLogicalFile functions */
00075   retcode = verify_direct_serialisation(context, file);
00076     
00077   /* test serialisation trough the generic GATObject functions */
00078   if (GAT_SUCCEEDED(retcode))
00079   {
00080     retcode = verify_generic_serialisation(context, file);
00081   }
00082   
00083   GATLogicalFile_Destroy (&file);
00084   GATLocation_Destroy    (&logfile);
00085   GATContext_Destroy     (&context);
00086 
00087   GAT_TEST_FINISH ();
00088 
00089   return retcode;
00090 }
00091 
00092 /* Local functions */
00093 
00094 /* test serialisation trough the direct GATLogicalFile functions */
00095 static GATResult
00096 verify_direct_serialisation(GATContext context, GATLogicalFile file)
00097 {
00098   GATResult      retcode     = GAT_FAIL;
00099   GATLogicalFile new_file    = NULL;
00100   GATBool        isequal     = GATFalse;
00101   char          *buffer      = NULL;
00102   GATuint32      buffer_size = 0;
00103 //  GATuint32      i           = NULL;
00104 
00105   GATMemoryStream stream     = NULL;
00106   
00107   GAT_TEST_START ("verify direct serialisation");
00108   
00109   stream = GATMemoryStream_Create(0, 0, GATFalse);
00110   GAT_TEST_TRACE (NULL != stream, context);
00111   
00112   retcode = GATLogicalFile_Serialise(file, GATMemoryStream_ToGATObject(stream), 
00113     GATTrue);
00114   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context)
00115 
00116   buffer = GATMemoryStream_GetBuffer(stream, &buffer_size, GATFalse);
00117   GAT_TEST_TRACE (buffer_size > 0, context);
00118   GAT_TEST_TRACE (NULL != buffer, context);
00119 
00120   /* reposition the stream */
00121   GATMemoryStream_Seek(stream, GATOrigin_Set, 0, 0);
00122   
00123   new_file = GATLogicalFile_DeSerialise(context, GATMemoryStream_ToGATObject(stream), 
00124     &retcode);
00125   GAT_TEST_TRACE (NULL != new_file, context);
00126   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00127   
00128   retcode = GATLogicalFile_Equals(file, new_file, &isequal);
00129   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00130   GAT_TEST_TRACE (GATTrue     == isequal, context);
00131 
00132   GATLogicalFile_Destroy  (&new_file);
00133   GATMemoryStream_Destroy (&stream);
00134   
00135   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00136 
00137   GAT_TEST_STOP ();
00138 
00139   return retcode;
00140 }
00141 
00142 /* test serialisation trough the generic GATObject functions */
00143 static GATResult 
00144 verify_generic_serialisation(GATContext context, GATLogicalFile file)
00145 {
00146   GATResult      retcode     = GAT_FAIL;
00147   GATLogicalFile new_file    = NULL;
00148   GATBool        isequal     = GATFalse;
00149   char          *buffer      = NULL;
00150   GATuint32      buffer_size = 0;
00151 //  GATuint32      i           = NULL;
00152   GATMemoryStream stream = NULL;
00153   
00154   GAT_TEST_START ("verify generic serialisation");
00155 
00156   stream = GATMemoryStream_Create(0, 0, GATFalse);
00157   GAT_TEST_TRACE (NULL != stream, context);
00158 
00159   retcode = GATSerialisable_Serialise(GATLogicalFile_ToGATObject  (file), 
00160                                 GATMemoryStream_ToGATObject (stream), 
00161                                 GATTrue);
00162   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00163 
00164   buffer = GATMemoryStream_GetBuffer(stream, &buffer_size, GATFalse);
00165   GAT_TEST_TRACE (NULL != buffer, context);
00166   GAT_TEST_TRACE (buffer_size > 0, context);
00167 
00168   /* reposition the stream */
00169   GATMemoryStream_Seek (stream, GATOrigin_Set, 0, 0);
00170   
00171   new_file = GATObject_ToGATLogicalFile 
00172                    (GATSerialisable_DeSerialise (context, 
00173                                            GATMemoryStream_ToGATObject(stream), 
00174                                            &retcode));
00175   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00176   GAT_TEST_TRACE (NULL != new_file, context)
00177   
00178   retcode = GATLogicalFile_Equals(file, new_file, &isequal);
00179   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00180   GAT_TEST_TRACE (GATTrue     == isequal, context);
00181 
00182   GATLogicalFile_Destroy  (&new_file);
00183   GATMemoryStream_Destroy (&stream);
00184 
00185   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00186 
00187   GAT_TEST_STOP ();
00188 
00189   return retcode;
00190 }
00191