GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATList_tests.c

Go to the documentation of this file.
00001 /** @file GATList_tests.c
00002  * Source file for some GATList test routines.
00003  *
00004  * @date Sat Sep 27 2003
00005  *
00006  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/internal/GATList_tests.c,v 1.27 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/GATList_tests.c,v 1.27 2004/04/20 17:04:43 hartmutkaiser Exp $"; 
00018 
00019 #include <assert.h>
00020 #include <string.h>
00021 
00022 #include "GAT.h"
00023 #include "GATMemoryStream.h"
00024 
00025 #include "GATTestUtils.h"
00026 
00027 /* define a list of int's: GATList_GATint32 */
00028 GATLIST_DEFINE(GATint32)
00029 
00030 /* define a list of lists of int's: GATList_GATList_GATint32 */
00031 GATLIST_DEFINE_LIST(GATList_GATint32)
00032 
00033 GATOBJECT_DEFINE_CONVERTERS_QUALIFIED(extern, GATList_GATint32, GATType_GATList);
00034 GATOBJECT_DEFINE_CONVERTERS_QUALIFIED(extern, GATList_GATList_GATint32,
00035   GATType_GATList);
00036 
00037 /* helper macros for this tests */
00038 #define countof(x)  (sizeof(x)/sizeof(x[0]))
00039 
00040 /* prototypes */
00041 
00042 /*
00043  *  Fill a integer list with the set of given values
00044  */
00045 static void
00046 fill_GATList_GATint32(GATList_GATint32 list, int *values, size_t count)
00047 {
00048   size_t i = 0;
00049   
00050   GAT_TEST_START("fill_GATList_GATint32");
00051 
00052   for (i = 0; i < count; ++i) 
00053   {
00054     GATList_GATint32_Iterator it = 
00055       GATList_GATint32_Insert(list, GATList_GATint32_End(list), values[i]);
00056     GAT_TEST(NULL != it);
00057   }
00058   
00059   GAT_TEST_STOP();
00060 }
00061 
00062 static void
00063 fill_GATList_String(GATList_String list, char const **values, size_t count)
00064 {
00065   size_t i = 0;
00066   
00067   GAT_TEST_START("fill_GATList_String");
00068 
00069   for (i = 0; i < count; ++i) 
00070   {
00071     GATList_String_Iterator it = 
00072       GATList_String_Insert(list, GATList_String_End(list), values[i]);
00073     GAT_TEST(NULL != it);
00074   }
00075   
00076   GAT_TEST_STOP();
00077 }
00078 
00079 /*
00080  *  Create and fill a list
00081  */
00082 static GATList_GATint32
00083 create_fill_GATList_GATint32(int *values, size_t count)
00084 {
00085   GATList_GATint32 list;
00086 
00087   GAT_TEST_START("create_fill_GATList_GATint32");
00088 
00089   list = GATList_GATint32_Create();
00090   GAT_TEST(NULL != list);  /* for testing needs: simply assert on a memory error */
00091   
00092 
00093   /* verify some basic characteristics */
00094   GAT_TEST(0 == GATList_GATint32_Size(list));
00095   GAT_TEST(GATList_GATint32_Begin(list) == GATList_GATint32_End(list));
00096   
00097   fill_GATList_GATint32(list, values, count);
00098   GAT_TEST(count == GATList_GATint32_Size(list));
00099 
00100   GAT_TEST_STOP();
00101   return list;
00102 }
00103 
00104 static GATList_String
00105 create_fill_GATList_String(char const **values, size_t count)
00106 {
00107   GATList_String list;
00108   
00109   GAT_TEST_START("create_fill_GATList_String");
00110 
00111   list = GATList_String_Create();
00112   GAT_TEST(NULL != list);  /* for testing needs: simply assert on a memory error */
00113   
00114 
00115   /* verify some basic characteristics */
00116   GAT_TEST(0 == GATList_String_Size(list));
00117   GAT_TEST(GATList_String_Begin(list) == GATList_String_End(list));
00118 
00119   fill_GATList_String(list, values, count);
00120   GAT_TEST(count == GATList_String_Size(list));
00121 
00122   GAT_TEST_STOP();
00123   return list;
00124 }
00125 
00126 /*
00127  *  Verify the contents of a given list
00128  */
00129 static void
00130 verify_GATList_GATint32(GATList_GATint32 list, int *values, size_t count)
00131 {
00132   GAT_TEST_START("verify_GATList_GATint32");
00133 
00134   /* verify it the direct way */
00135   {
00136     size_t i = 0;
00137     GATList_GATint32_Iterator ac = GATList_GATint32_Begin(list);
00138     
00139     GAT_TEST(count == GATList_GATint32_Size(list));
00140     
00141     for (i = 0; i < count; ++i) 
00142     {
00143       GAT_TEST(ac != GATList_GATint32_End(list));
00144       GAT_TEST(NULL != GATList_GATint32_Get(ac) && values[i] == *GATList_GATint32_Get(ac));
00145       
00146       ac = GATList_GATint32_Next(ac);
00147     }
00148     GAT_TEST(ac == GATList_GATint32_End(list));
00149   }
00150   
00151   /* verify it through GATList_*_Equals */
00152   {
00153     GATList_GATint32 list_copy = GATList_GATint32_Create();
00154     GATBool isequal = GATFalse;
00155     
00156     GAT_TEST(NULL != list_copy);
00157     
00158     fill_GATList_GATint32(list_copy, values, count);
00159 
00160     GAT_TEST(GAT_SUCCESS == GATList_GATint32_Equals(list, list_copy, &isequal));
00161     GAT_TEST(GATTrue == isequal);
00162     
00163     GATList_GATint32_Destroy(&list_copy);
00164   }
00165   GAT_TEST_STOP();
00166 }
00167 
00168 static void
00169 verify_GATList_String(GATList_String list, char const **values, size_t count)
00170 {
00171   GAT_TEST_START("verify_GATList_String");
00172 
00173   /* verify it the direct way */
00174   {
00175     size_t i = 0;
00176     GATList_String_Iterator ac = GATList_String_Begin (list);
00177     GAT_TEST (ac);
00178     
00179     GAT_TEST (count == GATList_String_Size (list));
00180     
00181     for (i = 0; i < count; ++i) 
00182     {
00183       GAT_TEST (ac != GATList_String_End (list));
00184       GAT_TEST (NULL != GATList_String_Get(ac));
00185       GAT_TEST (!strcmp(values[i], GATList_String_Get(ac)));
00186 
00187       ac = GATList_String_Next (ac);
00188       GAT_TEST (NULL != ac);
00189     }
00190     GAT_TEST (ac == GATList_String_End (list));
00191   }
00192   
00193   /* verify it through GATList_*_Equals */
00194   {
00195     GATBool isequal = GATFalse;
00196 
00197     GATList_String list_copy = GATList_String_Create();
00198     GAT_TEST (NULL != list_copy);
00199     
00200     fill_GATList_String (list_copy, values, count);
00201 
00202     GAT_TEST (GAT_SUCCESS == GATList_String_Equals (list, list_copy, &isequal));
00203     GAT_TEST (GATTrue     == isequal);
00204     
00205     GATList_String_Destroy (&list_copy);
00206   }
00207   
00208   GAT_TEST_STOP();
00209 }
00210 
00211 /* 
00212  *  Verify serialisation and de-serialisation of the GATList_String
00213  */
00214 static void
00215 verify_GATList_GATint32_serialization(GATContext context, 
00216   GATList_GATint32 list)
00217 {
00218   GATResult retval = GAT_FAIL;
00219   
00220   GAT_TEST_START("verify_GATList_GATint32_serialization");
00221 
00222   /* verify direct serialisation */
00223   {
00224     GATList_GATint32 new_list = NULL;
00225     GATBool isequal = GATFalse;
00226     GATObject stream_obj = NULL;
00227     
00228     GATMemoryStream stream = GATMemoryStream_Create(0, 0, GATFalse);
00229     GAT_TEST (NULL != stream);
00230     
00231     stream_obj = GATMemoryStream_ToGATObject(stream);
00232     GAT_TEST (NULL != stream_obj);
00233     
00234     /* serialise the list */
00235     retval = GATList_GATint32_Serialise (list, stream_obj, GATFalse);
00236     GAT_TEST (GAT_SUCCEEDED(retval));
00237     
00238     /* rewind the stream */
00239     retval = GATMemoryStream_Seek (stream, GATOrigin_Set, 0, 0);
00240     GAT_TEST (GAT_SUCCEEDED(retval));
00241     
00242     /* de-serialise the list */
00243     new_list = GATList_GATint32_DeSerialise (context, stream_obj, &retval);
00244     GAT_TEST (GAT_SUCCEEDED(retval));
00245     GAT_TEST (NULL != new_list);
00246 
00247     /* compare the two lists */
00248     retval = GATList_GATint32_Equals(list, new_list, &isequal);
00249     GAT_TEST (GAT_SUCCEEDED(retval));
00250     GAT_TEST (GATTrue == isequal);
00251     
00252     GATList_GATint32_Destroy (&new_list);
00253     GATMemoryStream_Destroy  (&stream);
00254   }
00255 
00256   /* verify generic serialisation */
00257   {
00258     GATList_GATint32 new_list = NULL;
00259     GATBool isequal = GATFalse;
00260     GATObject stream_obj = NULL;
00261     
00262     GATMemoryStream stream = GATMemoryStream_Create(0, 0, GATFalse);
00263     GAT_TEST (NULL != stream);
00264 
00265     stream_obj = GATMemoryStream_ToGATObject(stream);
00266     GAT_TEST (NULL != stream_obj);
00267     
00268     /* serialise the list */
00269     retval = GATSerialisable_Serialise (GATList_GATint32_ToGATObject(list), 
00270                                   stream_obj, GATFalse);
00271     GAT_TEST (GAT_SUCCEEDED(retval));
00272     
00273     /* rewind the stream */
00274     retval = GATMemoryStream_Seek (stream, GATOrigin_Set, 0, 0);
00275     GAT_TEST (GAT_SUCCEEDED(retval));
00276     
00277     /* de-serialise the list */
00278     new_list = GATObject_ToGATList_GATint32 (GATSerialisable_DeSerialise (context, stream_obj, &retval));
00279     GAT_TEST (GAT_SUCCEEDED(retval));
00280     GAT_TEST (NULL != new_list);
00281 
00282     /* compare the two lists */
00283     retval = GATList_GATint32_Equals(list, new_list, &isequal);
00284     GAT_TEST (GAT_SUCCEEDED(retval));
00285     GAT_TEST (GATTrue == isequal);
00286     
00287     GATList_GATint32_Destroy (&new_list);
00288     GATMemoryStream_Destroy  (&stream);
00289   }
00290 
00291   GAT_TEST_STOP ();
00292 }
00293 
00294 /* 
00295  *  Verify serialisation and de-serialisation of the GATList_String
00296  */
00297 static void
00298 verify_GATList_String_serialization(GATContext context, 
00299   GATList_String list)
00300 {
00301   GATResult retval = GAT_FAIL;
00302   
00303   GAT_TEST_START ("verify_GATList_String_serialization");
00304 
00305   /* verify direct serialisation */
00306   {
00307     GATList_String new_list = NULL;
00308     GATBool isequal = GATFalse;
00309     GATObject stream_obj = NULL;
00310     
00311     GATMemoryStream stream = GATMemoryStream_Create(0, 0, GATFalse);
00312     GAT_TEST (NULL != stream);
00313 
00314     stream_obj = GATMemoryStream_ToGATObject(stream);
00315     GAT_TEST (NULL != stream_obj);
00316     
00317     /* serialise the list */
00318     retval = GATList_String_Serialise (list, stream_obj, GATFalse);
00319     GAT_TEST (GAT_SUCCEEDED(retval));
00320     
00321     /* rewind the stream */
00322     retval = GATMemoryStream_Seek (stream, GATOrigin_Set, 0, 0);
00323     GAT_TEST (GAT_SUCCEEDED(retval));
00324     
00325     /* de-serialise the list */
00326     new_list = GATList_String_DeSerialise (context, stream_obj, &retval);
00327     GAT_TEST (GAT_SUCCEEDED(retval));
00328     GAT_TEST (NULL != new_list);
00329 
00330     /* compare the two lists */
00331     retval = GATList_String_Equals (list, new_list, &isequal);
00332     GAT_TEST (GAT_SUCCEEDED(retval));
00333     GAT_TEST (GATTrue == isequal);
00334     
00335     GATList_String_Destroy  (&new_list);
00336     GATMemoryStream_Destroy (&stream);
00337   }
00338 
00339   /* verify generic serialisation */
00340   {
00341     GATList_String new_list = NULL;
00342     GATBool isequal = GATFalse;
00343     GATObject stream_obj = NULL;
00344     
00345     GATMemoryStream stream = GATMemoryStream_Create (0, 0, GATFalse);
00346     GAT_TEST (NULL != stream);
00347 
00348     stream_obj = GATMemoryStream_ToGATObject (stream);
00349     GAT_TEST (NULL != stream_obj);
00350     
00351     /* serialise the list */
00352     retval = GATSerialisable_Serialise (GATList_String_ToGATObject (list), 
00353                                   stream_obj, GATFalse);
00354     GAT_TEST (GAT_SUCCEEDED(retval));
00355     
00356     /* rewind the stream */
00357     retval = GATMemoryStream_Seek (stream, GATOrigin_Set, 0, 0);
00358     GAT_TEST (GAT_SUCCEEDED(retval));
00359     
00360     /* de-serialise the list */
00361     new_list = GATObject_ToGATList_String (GATSerialisable_DeSerialise(context, stream_obj, &retval));
00362     GAT_TEST (GAT_SUCCEEDED(retval));
00363     GAT_TEST (NULL != new_list);
00364 
00365     /* compare the two lists */
00366     retval = GATList_String_Equals (list, new_list, &isequal);
00367     GAT_TEST (GAT_SUCCEEDED(retval));
00368     GAT_TEST (GATTrue     == isequal);
00369     
00370     GATList_String_Destroy  (&new_list);
00371     GATMemoryStream_Destroy (&stream);
00372   }
00373 
00374   GAT_TEST_STOP ();
00375 }
00376 
00377 /* 
00378  *  Verify serialisation and de-serialisation of the GATList_String
00379  */
00380 static void
00381 verify_GATList_GATList_GATint32_serialization(GATContext context, 
00382   GATList_GATList_GATint32 list)
00383 {
00384   GATResult retval = GAT_FAIL;
00385   
00386   GAT_TEST_START("verify_GATList_GATList_GATint32_serialization");
00387 
00388   /* verify direct serialisation */
00389   {
00390     GATList_GATList_GATint32 new_list = NULL;
00391     GATBool isequal = GATFalse;
00392     GATObject stream_obj = NULL;
00393     
00394     GATMemoryStream stream = GATMemoryStream_Create (0, 0, GATFalse);
00395     GAT_TEST (NULL != stream);
00396 
00397     stream_obj = GATMemoryStream_ToGATObject (stream);
00398     GAT_TEST (NULL != stream_obj);
00399     
00400     /* serialise the list */
00401     retval = GATList_GATList_GATint32_Serialise (list, stream_obj, GATFalse);
00402     GAT_TEST (GAT_SUCCEEDED(retval));
00403     
00404     /* rewind the stream */
00405     retval = GATMemoryStream_Seek (stream, GATOrigin_Set, 0, 0);
00406     GAT_TEST (GAT_SUCCEEDED(retval));
00407     
00408     /* de-serialise the list */
00409     new_list = GATList_GATList_GATint32_DeSerialise (context, stream_obj, &retval);
00410     GAT_TEST (GAT_SUCCEEDED(retval));
00411     GAT_TEST (NULL != new_list);
00412 
00413     /* compare the two lists */
00414     retval = GATList_GATList_GATint32_Equals (list, new_list, &isequal);
00415     GAT_TEST (GAT_SUCCEEDED(retval));
00416     GAT_TEST (GATTrue == isequal);
00417     
00418     GATList_GATList_GATint32_Destroy (&new_list);
00419     GATMemoryStream_Destroy          (&stream);
00420   }
00421 
00422   /* verify generic serialisation */
00423   {
00424     GATList_GATList_GATint32 new_list = NULL;
00425     GATBool isequal = GATFalse;
00426     GATObject stream_obj = NULL;
00427     
00428     GATMemoryStream stream = GATMemoryStream_Create(0, 0, GATFalse);
00429     GAT_TEST (NULL != stream);
00430 
00431     stream_obj = GATMemoryStream_ToGATObject(stream);
00432     GAT_TEST (NULL != stream_obj);
00433     
00434     /* serialise the list */
00435     retval = GATSerialisable_Serialise (GATList_GATList_GATint32_ToGATObject(list), 
00436                                   stream_obj, GATFalse);
00437     GAT_TEST (GAT_SUCCEEDED(retval));
00438     
00439     /* rewind the stream */
00440     retval = GATMemoryStream_Seek (stream, GATOrigin_Set, 0, 0);
00441     GAT_TEST (GAT_SUCCEEDED(retval));
00442     
00443     /* de-serialise the list */
00444     new_list = GATObject_ToGATList_GATList_GATint32 (GATSerialisable_DeSerialise (context, stream_obj, &retval));
00445     GAT_TEST (GAT_SUCCEEDED(retval));
00446     GAT_TEST (NULL != new_list);
00447 
00448     /* compare the two lists */
00449     retval = GATList_GATList_GATint32_Equals (list, new_list, &isequal);
00450     GAT_TEST (GAT_SUCCEEDED(retval));
00451     GAT_TEST (GATTrue     == isequal);
00452     
00453     GATList_GATList_GATint32_Destroy (&new_list);
00454     GATMemoryStream_Destroy          (&stream);
00455   }
00456   
00457   GAT_TEST_STOP ();
00458 }
00459 
00460 /*
00461  *  Return an Iterator, which is generated by incrementing a given Iterator
00462  *  a given amount of times.
00463  *  The caller has to ensure, that the result still lies inside the source list
00464  */
00465 static GATList_GATint32_Iterator
00466 advance_GATList_GATint32_Iterator (GATList_GATint32 list, 
00467                                    GATList_GATint32_Iterator it, 
00468                                    size_t count)
00469 {
00470   GAT_TEST_START ("GATList GATint32 Iterator advance");
00471 
00472   GAT_TEST (count <= GATList_GATint32_Size (list));
00473   
00474   while (count-- > 0)
00475   {
00476     GAT_TEST (it != GATList_GATint32_End (list));
00477     it = GATList_GATint32_Next (it);
00478     GAT_TEST (NULL != it);
00479   }
00480 
00481   GAT_TEST_STOP ();
00482 
00483   return (it);
00484 }
00485 
00486 static GATList_String_Iterator
00487 advance_GATList_String_Iterator (GATList_String list, 
00488                                  GATList_String_Iterator it, 
00489                                  size_t count)
00490 {
00491   GAT_TEST_START ("GATList String Iterator advance");
00492 
00493   GAT_TEST (count <= GATList_String_Size (list));
00494   
00495   while (count-- > 0)
00496   {
00497     GAT_TEST (it != GATList_String_End(list));
00498     it = GATList_String_Next (it);
00499     GAT_TEST (NULL != it);
00500   }
00501   
00502   GAT_TEST_STOP ();
00503 
00504   return (it);
00505 }
00506 
00507 /*
00508  *  Erase all elements of a list
00509  */
00510 static void
00511 erase_GATList_GATint32 (GATList_GATint32 list)
00512 {
00513   GATList_GATint32_Iterator ac = NULL;
00514   
00515   GAT_TEST_START ("GATList GATint32 erase");
00516 
00517   for (ac  = GATList_GATint32_Begin(list); 
00518        ac != GATList_GATint32_End(list); 
00519        /**/) 
00520   {
00521     size_t current_size = GATList_GATint32_Size (list);
00522     GATList_GATint32_Iterator next = GATList_GATint32_Next (ac);
00523 
00524     GAT_TEST (NULL != next);
00525     GAT_TEST (ac != GATList_GATint32_End (list));
00526     GAT_TEST (ac == GATList_GATint32_Previous (next));
00527 
00528     // TODO: retval?
00529     GATList_GATint32_Erase (list, ac);
00530     GAT_TEST (current_size - 1 == GATList_GATint32_Size (list));
00531     
00532     ac = next;
00533   }
00534 
00535   /* verify basic characteristics */
00536   GAT_TEST (0 == GATList_GATint32_Size (list));
00537   GAT_TEST (GATList_GATint32_Begin (list) == GATList_GATint32_End (list));
00538 
00539   GAT_TEST_STOP ();
00540 }
00541 
00542 static void
00543 erase_GATList_String(GATList_String list)
00544 {
00545   GATList_String_Iterator ac = NULL;
00546   
00547   GAT_TEST_START ("GATList String erase");
00548 
00549   for (ac = GATList_String_Begin(list); ac != GATList_String_End(list); /**/) 
00550   {
00551     size_t current_size = GATList_String_Size(list);
00552     GATList_String_Iterator next = GATList_String_Next(ac);
00553 
00554     GAT_TEST(ac != GATList_String_End(list));
00555     GAT_TEST(ac == GATList_String_Previous(next));
00556 
00557     GATList_String_Erase(list, ac);
00558     GAT_TEST(current_size - 1 == GATList_String_Size(list));
00559     
00560     ac = next;
00561   }
00562 
00563   /* verify basic characteristics */
00564   GAT_TEST(0 == GATList_String_Size(list));
00565   GAT_TEST(GATList_String_Begin(list) == GATList_String_End(list));
00566   GAT_TEST_STOP();
00567 }
00568 
00569 /*
00570  *  Test splice functionality
00571  */
00572 static void
00573 test_GATList_GATint32_Splice(void)
00574 {
00575   int values1[] = { 0, 1, 2, 3, 4 };
00576   int values2[] = { 5, 6, 7 };
00577   
00578   GAT_TEST_START("GATList splice test");
00579 
00580   /* test splicing of a whole list to the end of the first list */
00581   {
00582     int result[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
00583     GATList_GATint32 list1 = create_fill_GATList_GATint32(values1, countof(values1));
00584     GATList_GATint32 list2 = create_fill_GATList_GATint32(values2, countof(values2));
00585     
00586     GATList_GATint32_Splice(
00587       list1, GATList_GATint32_End(list1),
00588       list2, GATList_GATint32_Begin(list2), 0, 0
00589     );
00590     verify_GATList_GATint32(list1, result, countof(result));
00591     
00592     GATList_GATint32_Destroy(&list1);
00593     GATList_GATint32_Destroy(&list2);
00594   }
00595   
00596   /* test splicing of a part of a list into the list itself */
00597   {
00598     int result[] = { 3, 4, 0, 1, 2 };
00599     GATList_GATint32 list1 = create_fill_GATList_GATint32(values1, countof(values1));
00600     
00601     GATList_GATint32_Splice(
00602       list1, GATList_GATint32_Begin(list1),
00603       list1, advance_GATList_GATint32_Iterator(list1, GATList_GATint32_Begin(list1), 3), 
00604       0, 2
00605     );
00606     verify_GATList_GATint32(list1, result, countof(result));
00607     
00608     GATList_GATint32_Destroy(&list1);
00609   }
00610   GAT_TEST_STOP();
00611 }
00612 
00613 static void
00614 test_GATList_String_Splice(void)
00615 {
00616   char const *values1[] = { "0", "1", "2", "3", "4" };
00617   char const *values2[] = { "5", "6", "7" };
00618   
00619   GAT_TEST_START("test_GATList_String_Splice");
00620 
00621   /* test splicing of a whole list to the end of the first list */
00622   {
00623     char const *result[] = { "0", "1", "2", "3", "4", "5", "6", "7" };
00624     GATList_String list1 = create_fill_GATList_String(values1, countof(values1));
00625     GATList_String list2 = create_fill_GATList_String(values2, countof(values2));
00626     
00627     GATList_String_Splice(
00628       list1, GATList_String_End(list1),
00629       list2, GATList_String_Begin(list2), 0, 0
00630     );
00631     verify_GATList_String(list1, result, countof(result));
00632     
00633     GATList_String_Destroy(&list1);
00634     GATList_String_Destroy(&list2);
00635   }
00636   
00637   /* test splicing of a part of a list into the list itself */
00638   {
00639     char const *result[] = { "3", "4", "0", "1", "2" };
00640     GATList_String list1 = create_fill_GATList_String(values1, countof(values1));
00641     
00642     GATList_String_Splice(
00643       list1, GATList_String_Begin(list1),
00644       list1, 
00645       advance_GATList_String_Iterator(list1, GATList_String_Begin(list1), 3), 
00646       0, 2
00647     );
00648     verify_GATList_String(list1, result, countof(result));
00649     
00650     GATList_String_Destroy(&list1);
00651   }
00652   GAT_TEST_STOP();
00653 }
00654 
00655 /*
00656  *  Test a simple list, containing integers
00657  */
00658 static void 
00659 test_GATList_GATint32(GATContext context)
00660 {
00661   int values1[] = { 0, 1, 2, 3, 4 };
00662   GATList_GATint32 list1 = NULL;
00663   
00664   GAT_TEST_START("GATList GATint32 tests");
00665 
00666   /* create a new list of integers */
00667   list1 = create_fill_GATList_GATint32(values1, countof(values1));
00668   GAT_TEST (NULL != list1);
00669   
00670   /* verify the elements */
00671   // TODO: retval?
00672   verify_GATList_GATint32(list1, values1, countof(values1));
00673     
00674   /* verify serialization/de-serialisation */
00675   // TODO: retval?
00676   verify_GATList_GATint32_serialization (context, list1);
00677   
00678   /* erase all elements */
00679   // TODO: retval?
00680   erase_GATList_GATint32 (list1);
00681 
00682   /* destroy the whole list */
00683   // TODO: retval?
00684   GATList_GATint32_Destroy (&list1);
00685   
00686   /* Test splice functionality */
00687   // TODO: retval?
00688   test_GATList_GATint32_Splice ();
00689 
00690   GAT_TEST_STOP();
00691 }
00692 
00693 /* 
00694  *  User provided destroy function. Gets called, whenever a listelement is 
00695  *  removed from the list
00696  */
00697 static void 
00698 test_GATList_GATList_GATint32 (GATContext context)
00699 {
00700   int values1[] = { 0, 1, 2, 3, 4 };
00701   int values2[] = { 1, 2, 3, 4, 5 };
00702   int values3[] = { 2, 3, 4, 5, 6 };
00703   int values4[] = { 3, 4, 5, 6, 7 };
00704 
00705   GATList_GATint32 int_list1 = NULL;
00706   GATList_GATint32 int_list2 = NULL;
00707   GATList_GATint32 int_list3 = NULL;
00708   GATList_GATint32 int_list4 = NULL;
00709 
00710   int    *values[4]; 
00711   size_t  counts[4];
00712   GATList_GATint32         list_values[4];
00713   GATList_GATList_GATint32 list_list = NULL;
00714     
00715   GAT_TEST_START("GATList GATList GATint32 tests");
00716 
00717   int_list1 = create_fill_GATList_GATint32 (values1, countof(values1));
00718   int_list2 = create_fill_GATList_GATint32 (values2, countof(values2));
00719   int_list3 = create_fill_GATList_GATint32 (values3, countof(values3));
00720   int_list4 = create_fill_GATList_GATint32 (values4, countof(values4));
00721 
00722   GAT_TEST (NULL != int_list1);
00723   GAT_TEST (NULL != int_list2);
00724   GAT_TEST (NULL != int_list3);
00725   GAT_TEST (NULL != int_list4);
00726   
00727   list_list = GATList_GATList_GATint32_Create ();
00728   GAT_TEST (list_list);
00729   GAT_TEST (! GATList_GATList_GATint32_Size (list_list));
00730   GAT_TEST (GATList_GATList_GATint32_Begin  (list_list) == 
00731             GATList_GATList_GATint32_End    (list_list));
00732 
00733   /* fill in the arrays */
00734   values[0] = values1;
00735   values[1] = values2;
00736   values[2] = values3;
00737   values[3] = values4;
00738     
00739   counts[0] = countof (values1);
00740   counts[1] = countof (values2);
00741   counts[2] = countof (values3);
00742   counts[3] = countof (values4);
00743 
00744   list_values[0] = int_list1;
00745   list_values[1] = int_list2;
00746   list_values[2] = int_list3;
00747   list_values[3] = int_list4;
00748   
00749   /* fill the list of lists */
00750   {
00751     GATBool isequal = GATFalse;
00752     GATList_GATList_GATint32 list_list_copy = NULL;
00753     size_t i = 0;
00754     
00755     for (i = 0; i < countof(list_values); ++i) 
00756     {
00757       GATList_GATList_GATint32_Insert (list_list, 
00758                                        GATList_GATList_GATint32_End (list_list), 
00759                                        list_values[i]);
00760     }
00761     GAT_TEST (countof (list_values) == GATList_GATList_GATint32_Size (list_list));
00762   
00763     /* verify the contents of the list of lists by GATList_Equals */
00764     list_list_copy = GATList_GATList_GATint32_Create ();
00765     GAT_TEST (list_list_copy);
00766     
00767     for (i = 0; i < countof (list_values); ++i) 
00768     {
00769       GATList_GATList_GATint32_Insert (list_list_copy, 
00770                                        GATList_GATList_GATint32_End (list_list_copy), 
00771                                        list_values[i]);
00772     }
00773     GAT_TEST (countof (list_values) == GATList_GATList_GATint32_Size (list_list_copy));
00774     GAT_TEST (GAT_SUCCESS == GATList_GATList_GATint32_Equals (list_list, list_list_copy, &isequal));
00775     GAT_TEST (GATTrue == isequal);
00776     
00777     GATList_GATList_GATint32_Destroy (&list_list_copy);
00778   }
00779   
00780   /* verify the contents of the list of lists */
00781   {
00782     size_t i = 0;
00783     GATList_GATList_GATint32_Iterator ac = GATList_GATList_GATint32_Begin (list_list);
00784     GAT_TEST (NULL != ac);
00785 
00786     GAT_TEST (countof(list_values) == GATList_GATList_GATint32_Size (list_list));
00787 
00788     for (i = 0; i < countof (list_values); ++i) 
00789     {
00790       GATBool isequal = GATFalse;
00791       GATList_GATList_GATint32_Iterator next = NULL;
00792 
00793       GAT_TEST (ac != GATList_GATList_GATint32_End (list_list));
00794       GAT_TEST (NULL != GATList_GATList_GATint32_Get (ac));
00795 
00796       GATList_GATint32_Equals (list_values[i],
00797         *GATList_GATList_GATint32_Get(ac), 
00798         &isequal);
00799       GAT_TEST (GATTrue == isequal);
00800 
00801       verify_GATList_GATint32 (*GATList_GATList_GATint32_Get(ac), values[i], counts[i]);
00802 
00803       next = GATList_GATList_GATint32_Next (ac);
00804       GAT_TEST (ac == GATList_GATList_GATint32_Previous (next));
00805 
00806       ac = next;
00807     }
00808   
00809     GAT_TEST (ac == GATList_GATList_GATint32_End (list_list));
00810   }
00811 
00812   /* verify serialization/de-serialisation */
00813   // TODO: retval?
00814   verify_GATList_GATList_GATint32_serialization (context, list_list);
00815 
00816   /* remove the first two embedded lists */
00817   // TODO: retval??
00818   GATList_GATList_GATint32_Erase (list_list, GATList_GATList_GATint32_Begin(list_list));
00819   GATList_GATList_GATint32_Erase (list_list, GATList_GATList_GATint32_Begin(list_list));
00820 
00821   GAT_TEST(GATList_GATList_GATint32_Size (list_list) == countof (list_values)-2);
00822   
00823   /* verify the contents of the list of lists */
00824   {
00825     size_t i = 0;
00826     GATList_GATList_GATint32_Iterator ac = GATList_GATList_GATint32_Begin (list_list);
00827 
00828     GAT_TEST (NULL != ac);
00829     GAT_TEST (countof(list_values) - 2 == GATList_GATList_GATint32_Size (list_list));
00830 
00831     for (i = 2; i < countof (list_values); ++i) 
00832     {
00833       GATBool isequal = GATFalse;
00834       GATList_GATList_GATint32_Iterator next = NULL;
00835 
00836       GAT_TEST (ac != GATList_GATList_GATint32_End (list_list));
00837       GAT_TEST (GATList_GATList_GATint32_Get (ac));
00838 
00839       GATList_GATint32_Equals (list_values[i], 
00840         *GATList_GATList_GATint32_Get(ac), 
00841         &isequal);
00842       GAT_TEST (GATTrue == isequal);
00843 
00844       // TODO: retval?
00845       verify_GATList_GATint32 (*GATList_GATList_GATint32_Get (ac), values[i], counts[i]);
00846 
00847       next = GATList_GATList_GATint32_Next (ac);
00848       GAT_TEST (NULL != next);
00849       GAT_TEST (ac == GATList_GATList_GATint32_Previous (next));
00850 
00851       ac = next;
00852     }
00853 
00854     GAT_TEST (ac == GATList_GATList_GATint32_End (list_list));
00855   }
00856   
00857   
00858   /* Splice the second element in the list to the beginning */
00859   GATList_GATList_GATint32_Splice(list_list, GATList_GATList_GATint32_Begin(list_list),
00860     list_list, GATList_GATList_GATint32_Next(GATList_GATList_GATint32_Begin(list_list)),
00861     0, 1);
00862   
00863   /* verify the contents of the list of lists */
00864   {
00865     size_t i = 0;
00866     GATList_GATList_GATint32_Iterator ac = GATList_GATList_GATint32_Begin (list_list);
00867 
00868     GAT_TEST (NULL != ac);
00869     GAT_TEST (countof (list_values)-2 == GATList_GATList_GATint32_Size (list_list));
00870     
00871     for (i = 2; i < countof(list_values); ++i) 
00872     {
00873       GATBool isequal = GATFalse;
00874       GATList_GATList_GATint32_Iterator next = NULL;
00875 
00876       GAT_TEST (ac != GATList_GATList_GATint32_End (list_list));
00877       GAT_TEST (GATList_GATList_GATint32_Get (ac));
00878       
00879       GATList_GATint32_Equals (list_values[(i == 2) ? 3 : 2], 
00880                                *GATList_GATList_GATint32_Get(ac),
00881                                &isequal);
00882       GAT_TEST (GATTrue == isequal);
00883 
00884       // TODO: retval?
00885       verify_GATList_GATint32 (*GATList_GATList_GATint32_Get(ac), 
00886                                values[(i == 2) ? 3 : 2], 
00887                                counts[(i == 2) ? 3 : 2]);
00888       
00889       next = GATList_GATList_GATint32_Next(ac);
00890 
00891       GAT_TEST (NULL != next);
00892       GAT_TEST (ac == GATList_GATList_GATint32_Previous (next));
00893       
00894       ac = next;
00895     }
00896     
00897     GAT_TEST (ac == GATList_GATList_GATint32_End (list_list));
00898   }
00899     
00900   GATList_GATint32_Destroy (&int_list4);
00901   GATList_GATint32_Destroy (&int_list3);
00902   GATList_GATint32_Destroy (&int_list2);
00903   GATList_GATint32_Destroy (&int_list1);
00904   GATList_GATList_GATint32_Destroy (&list_list);
00905   
00906   GAT_TEST_STOP();
00907 }    
00908 
00909 static void
00910 test_GATList_String(GATContext context)
00911 {
00912   char const *values1[] = { "0", "1", "2", "3", "4" };
00913   GATList_String list1 = NULL;
00914   
00915   GAT_TEST_START("GATList String Tests");
00916 
00917   /* create a new list of strings */
00918   list1 = create_fill_GATList_String (values1, countof(values1));
00919   GAT_TEST (NULL != list1);
00920   
00921   /* verify the elements */
00922   // TODO: retval?
00923   verify_GATList_String(list1, values1, countof(values1));
00924 
00925   /* verify serialization/de-serialisation */
00926   // TODO: retval?
00927   verify_GATList_String_serialization(context, list1);
00928   
00929   /* erase all elements */
00930   // TODO: retval?
00931   erase_GATList_String (list1);
00932 
00933   /* destroy the whole list */
00934   GATList_String_Destroy (&list1);
00935   
00936   /* Test splice functionality */
00937   test_GATList_String_Splice ();
00938 
00939   GAT_TEST_STOP();
00940 }
00941 
00942 /*
00943  *  main entry point for this tests
00944  */
00945 int main (void)
00946 {
00947   GATContext context = NULL;
00948   
00949   GAT_TEST_INIT (-1);
00950   GAT_TEST_SUITE ("GAT List");
00951 
00952   context = GATContext_Create ();
00953   GAT_TEST(NULL != context);
00954   
00955   /* the following test makes sure, that there were no errors during the 
00956      creation of the GATContext object */
00957   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00958 
00959   test_GATList_GATint32         (context);
00960   test_GATList_GATList_GATint32 (context);
00961   test_GATList_String           (context);
00962 
00963   GATContext_Destroy (&context);
00964   
00965   GAT_TEST_FINISH ();
00966 
00967   return 0;
00968 }
00969