GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

timeperiod_serialisation_tests.c

Go to the documentation of this file.
00001 /** @file timeperiod_serialisation_tests.c
00002  *  Tests the GATTimePeriodPeriod serialisation functionality.
00003  * 
00004  *  @date Thu Dec 18 2003
00005  * 
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/internal/timeperiod_serialisation_tests.c,v 1.5 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/timeperiod_serialisation_tests.c,v 1.5 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 #include "GATTestUtils.h"
00029 
00030 /* Macros */
00031 
00032 /* Structures, unions and enums */
00033 
00034 /* Static function prototypes */
00035 static 
00036   GATResult verify_direct_serialisation  (GATContext context, GATTimePeriod file);
00037 static  
00038   GATResult verify_generic_serialisation (GATContext context, GATTimePeriod file);
00039 
00040 /* File scope variables */
00041 
00042 /* External functions */
00043 
00044 int main(void)
00045 {
00046   GATResult retcode = GAT_SUCCESS;
00047   GATContext context = NULL;
00048   GATTimePeriod timeobj = NULL;
00049   
00050   GAT_TEST_INIT  (-1);
00051   GAT_TEST_SUITE ("Timeperiod Serialization");
00052 
00053   context = GATContext_Create();
00054   GAT_TEST(NULL != context);
00055   
00056   /* the following test makes sure, that there were no errors during the 
00057      creation of the GATContext object */
00058   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00059 
00060   GAT_TEST_START ("Timeperiod serialization Tests");
00061   
00062   timeobj = GATTimePeriod_Create(0);    /* use the current time */
00063   GAT_TEST (NULL != timeobj);
00064 
00065   GAT_TEST_STOP();
00066   
00067   /* test serialisation trough the direct GATTimePeriod functions */
00068   retcode = verify_direct_serialisation(context, timeobj);
00069     
00070   /* test serialisation trough the generic GATObject functions */
00071   retcode = verify_generic_serialisation(context, timeobj);
00072 
00073   GATTimePeriod_Destroy(&timeobj);
00074   GATContext_Destroy(&context);
00075 
00076   GAT_TEST_FINISH();
00077   return retcode;
00078 }
00079 
00080 /* Local functions */
00081 
00082 /* test serialisation trough the direct GATLogicalFile functions */
00083 static GATResult
00084 verify_direct_serialisation(GATContext context, GATTimePeriod timeobj)
00085 {
00086   GATResult retcode = GAT_FAIL;
00087   GATTimePeriod new_time = NULL;
00088   GATBool isequal = GATFalse;
00089   char *buffer = NULL;
00090   GATuint32 buffer_size = 0;
00091 
00092   GATMemoryStream stream = NULL;
00093   
00094   GAT_TEST_START ("verify direct serialisation");
00095   
00096   stream = GATMemoryStream_Create(0, 0, GATFalse);
00097   GAT_TEST(NULL != stream);
00098   
00099   retcode = GATTimePeriod_Serialise(timeobj, GATMemoryStream_ToGATObject(stream), 
00100     GATTrue);
00101   GAT_TEST(GAT_SUCCEEDED(retcode))
00102 
00103   buffer = GATMemoryStream_GetBuffer(stream, &buffer_size, GATFalse);
00104   GAT_TEST(buffer_size > 0);
00105   GAT_TEST(NULL != buffer);
00106 
00107   /* reposition the stream */
00108   retcode = GATMemoryStream_Seek(stream, GATOrigin_Set, 0, 0);
00109   GAT_TEST(GAT_SUCCEEDED(retcode))
00110 
00111   new_time = GATTimePeriod_DeSerialise(context, GATMemoryStream_ToGATObject(stream), 
00112     &retcode);
00113   GAT_TEST(NULL != new_time);
00114   GAT_TEST(GAT_SUCCEEDED(retcode))
00115   
00116   retcode = GATTimePeriod_Equals(timeobj, new_time, &isequal);
00117   GAT_TEST(GAT_SUCCEEDED(retcode))
00118   GAT_TEST(GATTrue == isequal);
00119 
00120   GATTimePeriod_Destroy(&new_time);
00121   GATMemoryStream_Destroy(&stream);
00122 
00123   GAT_TEST_STOP();
00124   return retcode;
00125 }
00126 
00127 /* test serialisation trough the generic GATObject functions */
00128 static GATResult 
00129 verify_generic_serialisation(GATContext context, GATTimePeriod timeobj)
00130 {
00131   GATResult retcode     = GAT_FAIL;
00132   GATTimePeriod new_time = NULL;
00133   GATBool isequal     = GATFalse;
00134   char *buffer      = NULL;
00135   GATuint32 buffer_size = 0;
00136   GATMemoryStream stream = NULL;
00137   
00138   GAT_TEST_START ("verify generic serialisation");
00139 
00140   stream = GATMemoryStream_Create(0, 0, GATFalse);
00141   GAT_TEST(NULL != stream);
00142 
00143   retcode = GATSerialisable_Serialise(GATTimePeriod_ToGATObject(timeobj), 
00144     GATMemoryStream_ToGATObject(stream), GATTrue);
00145   GAT_TEST(GAT_SUCCEEDED(retcode))
00146 
00147   buffer = GATMemoryStream_GetBuffer(stream, &buffer_size, GATFalse);
00148   GAT_TEST(NULL != buffer);
00149   GAT_TEST(buffer_size > 0);
00150 
00151   /* reposition the stream */
00152   retcode = GATMemoryStream_Seek (stream, GATOrigin_Set, 0, 0);
00153   GAT_TEST(GAT_SUCCEEDED(retcode))
00154 
00155   new_time = GATObject_ToGATTimePeriod(GATSerialisable_DeSerialise (context, 
00156     GATMemoryStream_ToGATObject(stream), &retcode));
00157   GAT_TEST(GAT_SUCCEEDED(retcode))
00158   GAT_TEST(NULL != new_time)
00159   
00160   retcode = GATTimePeriod_Equals(timeobj, new_time, &isequal);
00161   GAT_TEST(GAT_SUCCEEDED(retcode))
00162   GAT_TEST(GATTrue == isequal);
00163 
00164   GATTimePeriod_Destroy(&new_time);
00165   GATMemoryStream_Destroy(&stream);
00166 
00167   GAT_TEST_STOP();
00168   return retcode;
00169 }
00170