GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATStatus_tests.c

Go to the documentation of this file.
00001 /** @file GATStatus_tests.c
00002  * Source file for minimal GATStatus tests.
00003  *
00004  * @date Tue Sep 30 2003
00005  *
00006  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/internal/GATStatus_tests.c,v 1.21 2004/04/28 10:55:19 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/GATStatus_tests.c,v 1.21 2004/04/28 10:55:19 hartmutkaiser Exp $";
00018 
00019 #include <stdio.h>
00020 #include <memory.h>
00021 
00022 #include "GAT.h"
00023 #include "GATErrors.h"
00024 #include "GATStatus.h"
00025 #include "GATMemoryStream.h"
00026 
00027 #include "GATTestUtils.h"
00028 
00029 static GATStatus
00030 create_status(int code, char const *message, char const *filename, 
00031   GATuint32 lineno)
00032 {
00033   GATStatus status;
00034 
00035   GAT_TEST_START(message);
00036 
00037   status = GATStatus_Create(message, filename, lineno);
00038   GAT_TEST(NULL != message);
00039 
00040   GATStatus_SetStatusCode(status, code);
00041 
00042   GAT_TEST_STOP();
00043   return status;
00044 }
00045 
00046 static void print_status (GATContext context, GATStatus status, int level)
00047 {
00048   GATResult code = GAT_SUCCESS;
00049   
00050   GAT_TEST_START ("GAT Status get tests");
00051 
00052   code = GATStatus_GetStatusCode(status);
00053 
00054   /* print out all attached messages */
00055   {
00056     GATList_String_const messages = GATStatus_GetMessages(status);
00057     GATList_String_Iterator msg = GATList_String_Begin(messages);
00058     GATList_String_Iterator msg_end = GATList_String_End(messages);
00059     int i;
00060     
00061     for (i = 0; msg != msg_end; msg = GATList_String_Next(msg), ++i)
00062     {
00063       GAT_TEST_TRACE(0 != strcmp("", GATList_String_Get(msg)), context);
00064     }
00065   }
00066       
00067   /* print out the information for all attached children */  
00068   {
00069     GATList_GATStatus_const children = GATStatus_GetChildren(status);
00070     if (NULL != children)
00071     {
00072       GATList_GATStatus_Iterator it = GATList_GATStatus_Begin(children);
00073       GATList_GATStatus_Iterator end = GATList_GATStatus_End(children);
00074       int j;
00075       
00076       for (j = 0; it != end; it = GATList_GATStatus_Next(it), ++j)
00077       {
00078         GATStatus child = *GATList_GATStatus_Get(it);
00079 
00080         /* ensure the consistency of the hierarchy */
00081         GAT_TEST_TRACE(NULL != child, context);
00082         GAT_TEST_TRACE(GATStatus_GetParent(child) == status, context);
00083 
00084         /* print out any information of this child */        
00085         print_status(context, child, level + 1);
00086       }
00087     }  
00088   }
00089 
00090   GAT_TEST_STOP();
00091 }
00092 
00093 int main (void)
00094 {
00095   GATContext context = NULL;
00096   GATResult retval = GAT_FAIL;
00097   GATStatus parent = NULL;
00098   GATStatus child1 = NULL;
00099   GATStatus child2 = NULL;
00100 
00101   GAT_TEST_INIT (-1);
00102   GAT_TEST_SUITE ("GAT Status");
00103 
00104   context = GATContext_Create();
00105   GAT_TEST(NULL != context);
00106   
00107   /* the following test makes sure, that there were no errors during the 
00108      creation of the GATContext object */
00109   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00110 
00111   parent = create_status (GAT_FAIL, "Create GAT_FAIL status", 
00112     __FILE__, __LINE__);
00113   child1 = create_status (GAT_MEMORYFAILURE, "Create GAT_MEMORYFAILURE status", 
00114     __FILE__, __LINE__);
00115   child2 = create_status (GAT_DUPLICATE_ADAPTOR, "Create GAT_DUPLICATE_ADAPTOR status", 
00116     __FILE__, __LINE__);
00117 
00118   GAT_TEST_START ("GAT Status Tests");
00119 
00120   GAT_TEST_TRACE(NULL != parent, context);
00121   GAT_TEST_TRACE(NULL != child1, context);
00122   GAT_TEST_TRACE(NULL != child2, context);
00123 
00124   /* Add some additional messages */
00125   retval = GATStatus_AddMessage (parent, "Some additional error message 1 (parent).");
00126   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00127   
00128   retval = GATStatus_AddMessage (parent, "Some additional error message 2 (parent).");
00129   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00130   
00131   retval = GATStatus_AddMessage (child1, "Some additional error message 1 (child1).");
00132   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00133   
00134   retval = GATStatus_AddMessage (child1, "Some additional error message 2 (child1).");
00135   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00136   
00137   retval = GATStatus_AddMessage (child2, "Some additional error message 1 (child2).");
00138   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00139   
00140   retval = GATStatus_AddMessage (child2, "Some additional error message 2 (child2).");
00141   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00142 
00143   /* Add the children to the parent */
00144   retval = GATStatus_AddChild (parent, child1);
00145   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00146   
00147   retval = GATStatus_AddChild (parent, child2);
00148   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00149 
00150   GATStatus_Destroy (&child1);     /* were cloned inside AddChild */
00151   GATStatus_Destroy (&child2);
00152   
00153   GAT_TEST_STOP   ();
00154 
00155   /* Traverse the GATStatus hierarchy */
00156   // printf("Original GATStatus:\n");
00157   print_status (context, parent, 0);
00158 
00159   GAT_TEST_START ("GAT Status Tests");
00160 
00161   /* Clone the status object */
00162   {
00163     GATStatus cloned = NULL;
00164     GATBool isequal = GATFalse;
00165     
00166     retval = GATStatus_Clone(parent, &cloned);
00167     GAT_TEST_TRACE(GAT_SUCCEEDED(retval) && NULL != cloned, context);
00168 
00169     print_status(context, cloned, 0);
00170 
00171     retval = GATStatus_Equals(parent, cloned, &isequal); 
00172     GAT_TEST_TRACE(GAT_SUCCEEDED(retval) && GATTrue == isequal, context);   
00173     
00174     GATStatus_Destroy(&cloned);
00175   }
00176   
00177   GAT_TEST_STOP();
00178   
00179   GAT_TEST_START("GAT Status Serialisation Tests (direct)");
00180   {
00181     GATStatus cloned = NULL;
00182     GATMemoryStream stream = GATMemoryStream_Create (0, 0, GATFalse);
00183     char *buffer = NULL;
00184     GATuint32 buffer_size = 0;
00185     GATBool isequal = GATFalse;
00186 
00187     retval = GATStatus_Serialise(parent, GATMemoryStream_ToGATObject(stream), 
00188       GATTrue);
00189     GAT_TEST(retval == GAT_SUCCESS);
00190 
00191     buffer = GATMemoryStream_GetBuffer (stream, &buffer_size, GATFalse);
00192     GAT_TEST_TRACE(NULL != buffer, context);
00193     GAT_TEST_TRACE(buffer_size > 0, context);
00194 
00195     /* reposition the stream */
00196     GATMemoryStream_Seek(stream, GATOrigin_Set, 0, 0);
00197     
00198     cloned = GATStatus_DeSerialise(context, GATMemoryStream_ToGATObject(stream), 
00199       &retval);
00200     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00201     GAT_TEST_TRACE(NULL != cloned, context);
00202     
00203     retval = GATStatus_Equals(parent, cloned, &isequal);
00204     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00205     GAT_TEST_TRACE(GATTrue == isequal, context);
00206 
00207     GATStatus_Destroy(&cloned);
00208     GATMemoryStream_Destroy(&stream);
00209   }
00210   GAT_TEST_STOP();
00211   
00212   GAT_TEST_START("GAT Status Serialisation Tests (generic)");
00213   {
00214     GATStatus cloned = NULL;
00215     GATMemoryStream stream = GATMemoryStream_Create(0, 0, GATFalse);
00216     char *buffer = NULL;
00217     GATuint32 buffer_size = 0;
00218     GATBool isequal = GATFalse;
00219 
00220     retval = GATSerialisable_Serialise(GATStatus_ToGATObject(parent), 
00221       GATMemoryStream_ToGATObject(stream), GATFalse);
00222     GAT_TEST_TRACE(retval == GAT_SUCCESS, context);
00223 
00224     buffer = GATMemoryStream_GetBuffer (stream, &buffer_size, GATFalse);
00225     GAT_TEST_TRACE(NULL != buffer, context);
00226     GAT_TEST_TRACE(buffer_size > 0, context);
00227 
00228     /* reposition the stream */
00229     GATMemoryStream_Seek(stream, GATOrigin_Set, 0, 0);
00230     
00231     cloned = GATObject_ToGATStatus(GATSerialisable_DeSerialise(context, 
00232       GATMemoryStream_ToGATObject(stream), &retval));
00233     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00234     GAT_TEST_TRACE(NULL != cloned, context);
00235     
00236     retval = GATStatus_Equals(parent, cloned, &isequal);
00237     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00238     GAT_TEST_TRACE(GATTrue == isequal, context);
00239 
00240     GATStatus_Destroy(&cloned);
00241     GATMemoryStream_Destroy(&stream);
00242   }
00243   GAT_TEST_STOP();
00244   
00245   /* Destroy the GATStatus objects */
00246   GATStatus_Destroy (&parent);    /* acts recursively */
00247   GATContext_Destroy(&context);
00248   
00249   GAT_TEST_FINISH ();
00250 
00251   return 0;
00252 }
00253