GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

pipe_write_tests.c

Go to the documentation of this file.
00001 /** @file pipe_write_tests.c
00002  *  Test GATEndpoint and GATPipe API's related to GATPipe_Write
00003  * 
00004  *  @date Tue Mar 30 2004
00005  * 
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/pipe_write_tests.c,v 1.1 2004/05/07 09:41:59 merzky 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/simple/pipe_write_tests.c,v 1.1 2004/05/07 09:41:59 merzky 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 "GATTestUtils.h"
00028 
00029 /* Macros */
00030 
00031 /* Structures, unions and enums */
00032 
00033 /* Static function prototypes */
00034 
00035 /* File scope variables */
00036 
00037 /* External functions */
00038 
00039 int main(int argc, const char * const argv[])
00040 {
00041   GATResult retval = GAT_FAIL;
00042   GATContext context = NULL;
00043   GATAdvertService advert = NULL; 
00044   GATEndpoint endpoint = NULL;
00045   GATList_String paths = NULL;
00046   GATTable metadata = NULL;
00047   GATPipe connected_pipe = NULL;
00048   char const *pathstr = "/Ann/GAT/Endpoints";
00049   GATuint32 written_bytes = 0;
00050   char const *data = "Hello GAT Endpoint world!";
00051   
00052   GAT_TEST_INIT  (-1);
00053   GAT_TEST_SUITE ("GAT Pipe Connect");
00054   
00055   context = GATContext_Create();
00056   GAT_TEST (NULL != context);
00057 
00058   /* the following test makes sure, that there were no errors during the 
00059      creation of the GATContext object */
00060   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00061 
00062   GAT_TEST_START ("GAT Pipe Write Tests");
00063 
00064   /* create the advert service object */
00065   advert = GATAdvertService_Create(context, NULL);
00066   GAT_TEST_TRACE(NULL != advert, context);
00067 
00068   /* create the metadata to look for */
00069   metadata = GATTable_Create();
00070   GAT_TEST(NULL != metadata);
00071   
00072   retval = GATTable_Add_String(metadata, "GAT_TYPE", "GATEndpoint");
00073   GAT_TEST(GAT_SUCCEEDED(retval));
00074   retval = GATTable_Add_String(metadata, "application", "A");
00075   GAT_TEST(GAT_SUCCEEDED(retval));
00076   retval = GATTable_Add_String(metadata, "owner", "Ann_1");
00077   GAT_TEST(GAT_SUCCEEDED(retval));
00078   retval = GATTable_Add_String(metadata, "capability", "test");
00079   GAT_TEST(GAT_SUCCEEDED(retval));
00080   
00081   /* fin d all matching entries (should be at least one!) */
00082   retval = GATAdvertService_Find(advert, metadata, &paths);
00083   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00084 
00085   /* get the advertised endpoint object */
00086   {
00087     GATObject object = NULL;
00088     GATString path = NULL;
00089     char const *found_path = NULL;
00090     GATList_String_Iterator firstpath = GATList_String_Begin(paths);
00091     GATList_String_Iterator lastpath = GATList_String_End(paths);
00092     
00093     GAT_TEST(firstpath != lastpath);
00094   
00095     found_path = GATList_String_Get(firstpath);
00096     GAT_TEST(NULL != found_path);
00097     
00098     path = GATString_Create(found_path, (GATuint32)strlen(found_path)+1, 
00099       "ASCII");
00100     GAT_TEST(NULL != path);
00101     
00102     retval = GATAdvertService_GetAdvertisable(advert, path, &object);
00103     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00104     
00105     endpoint = GATObject_ToGATEndpoint(object);
00106     GAT_TEST(NULL != endpoint);
00107   
00108     GATString_Destroy(&path);
00109   }
00110   
00111   /* create the pipe to listen to (waits until someone connects) */
00112   retval = GATEndpoint_Connect(endpoint, &connected_pipe);
00113   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00114 
00115   /* read the incoming message */
00116   retval = GATPipe_Write(connected_pipe, data, (GATuint32)strlen(data)+1, 
00117     &written_bytes);
00118   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00119   GAT_TEST_TRACE(written_bytes == strlen(data)+1, context);
00120   
00121   GAT_TEST_STOP ();
00122 
00123   GATList_String_Destroy(&paths);
00124   GATPipe_Destroy(&connected_pipe);
00125   GATTable_Destroy(&metadata);
00126   GATEndpoint_Destroy(&endpoint);
00127   GATAdvertService_Destroy(&advert);
00128   GATContext_Destroy(&context);
00129 
00130   GAT_TEST_FINISH ();
00131 
00132   return retval;
00133 }
00134