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_read_tests.c

Go to the documentation of this file.
00001 /** @file pipe_read_tests.c
00002  *  Test GATEndpoint and GATPipe API's related to GATPipe_Read
00003  *
00004  *  @date Tue Mar 30 2004
00005  * 
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/pipe_read_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_read_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 #include <unistd.h>
00024 #include <sys/wait.h>
00025 
00026 /* GAT Header Files */
00027 
00028 #include "GAT.h"
00029 #include "GATTestUtils.h"
00030 
00031 /* Macros */
00032 
00033 /* Structures, unions and enums */
00034 
00035 /* Static function prototypes */
00036 
00037 /* File scope variables */
00038 
00039 /* External functions */
00040 
00041 int main(int argc, const char * const argv[])
00042 {
00043   GATResult retval = GAT_FAIL;
00044   GATContext context = NULL;
00045   GATAdvertService advert = NULL; 
00046   GATEndpoint endpoint = NULL;
00047   GATString path = NULL;
00048   GATTable metadata = NULL;
00049   GATPipe listener_pipe = NULL;
00050   char buffer[256];
00051   GATuint32 got_bytes = 0;
00052   char const *pathstr = "/Ann/GAT/Endpoints/EP1";
00053   char const *data = "Hello GAT Endpoint world!";   // expected data
00054   
00055   GAT_TEST_INIT  (-1);
00056   GAT_TEST_SUITE ("GAT Pipe Listen");
00057   
00058   context = GATContext_Create();
00059   GAT_TEST (NULL != context);
00060 
00061   /* the following test makes sure, that there were no errors during the 
00062      creation of the GATContext object */
00063   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00064 
00065   GAT_TEST_START ("GAT Pipe Read Tests");
00066 
00067   /* create the advert service object */
00068   advert = GATAdvertService_Create(context, NULL);
00069   GAT_TEST_TRACE(NULL != advert, context);
00070 
00071   /* create the endpoint object to advertise */  
00072   endpoint = GATEndpoint_Create(context, NULL);
00073   GAT_TEST_TRACE(NULL != endpoint, context);
00074   
00075   /* create the path, where to advertise the endpoint */
00076   path = GATString_Create(pathstr, (GATuint32)strlen(pathstr)+1, "ASCII");
00077   GAT_TEST(NULL != path);
00078   
00079   /* advertise the endpoint object */
00080   metadata = GATTable_Create();
00081   GAT_TEST(NULL != metadata);
00082   
00083   retval = GATTable_Add_String(metadata, "name", "myEndpoint");
00084   GAT_TEST(GAT_SUCCEEDED(retval));
00085   retval = GATTable_Add_String(metadata, "application", "A");
00086   GAT_TEST(GAT_SUCCEEDED(retval));
00087   retval = GATTable_Add_String(metadata, "owner", "Ann_1");
00088   GAT_TEST(GAT_SUCCEEDED(retval));
00089   retval = GATTable_Add_String(metadata, "capability", "test");
00090   GAT_TEST(GAT_SUCCEEDED(retval));
00091   
00092   retval = GATAdvertService_Add(advert, GATEndpoint_ToGATObject_const(endpoint),
00093     metadata, path);
00094   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00095 
00096   /* create the pipe to listen to (waits until someone connects) */
00097   retval = GATEndpoint_Listen(endpoint, &listener_pipe);
00098   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00099 
00100   /* read the incoming message */
00101   retval = GATPipe_Read(listener_pipe, buffer, sizeof(buffer), &got_bytes);
00102   GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00103   
00104   GAT_TEST(!strcmp(buffer, data));
00105   
00106   GAT_TEST_STOP ();
00107 
00108   GATString_Destroy(&path);
00109   GATPipe_Destroy(&listener_pipe);
00110   GATTable_Destroy(&metadata);
00111   GATEndpoint_Destroy(&endpoint);
00112   GATAdvertService_Destroy(&advert);
00113   GATContext_Destroy(&context);
00114 
00115   GAT_TEST_FINISH ();
00116 
00117   return retval;
00118 }
00119