00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/internal/softwaredescription_tests.c,v 1.15 2004/04/20 17:04:43 hartmutkaiser Exp $";
00018
00019
00020 #include <stdio.h>
00021 #include <string.h>
00022
00023
00024 #include "GAT.h"
00025
00026 #include "GATTestUtils.h"
00027
00028
00029
00030
00031
00032
00033 static GATSoftwareDescription
00034 get_sw_description_direct(GATContext context, int argc, char *argv[]);
00035
00036 static GATFile
00037 create_gatfile(GATContext context, char const *name);
00038
00039 static void
00040 test_sw_attributes(GATSoftwareDescription_const sw_desc, int argc, char *argv[]);
00041
00042 static void
00043 test_std_file_attriutes(GATTable_const attributes, char const *filename);
00044
00045
00046
00047
00048 int main (int argc, char *argv[])
00049 {
00050 GATContext context = NULL;
00051 GATBool isequal = GATFalse;
00052 GATResult retval = GAT_FAIL;
00053 GATSoftwareDescription sw_desc1 = NULL;
00054 GATSoftwareDescription sw_desc2 = NULL;
00055
00056 GAT_TEST_INIT (-1);
00057 GAT_TEST_SUITE ("Software Description");
00058
00059 context = GATContext_Create ();
00060 GAT_TEST(NULL != context);
00061
00062
00063
00064 GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00065
00066 sw_desc1 = get_sw_description_direct (context, argc, argv);
00067
00068 GAT_TEST_START ("Software Description Tests");
00069 retval = GATSoftwareDescription_Clone (sw_desc1, &sw_desc2);
00070
00071 GAT_TEST (GAT_SUCCEEDED(retval));
00072 GAT_TEST (NULL != sw_desc2);
00073
00074
00075 isequal = GATFalse;
00076 retval = GATSoftwareDescription_Equals (sw_desc1, sw_desc2, &isequal);
00077 GAT_TEST (GAT_SUCCEEDED(retval));
00078 GAT_TEST (GATTrue == isequal);
00079
00080
00081 {
00082 GATTable_const a = GATSoftwareDescription_GetAttributes(sw_desc1);
00083 GATTable_const b = GATSoftwareDescription_GetAttributes(sw_desc2);
00084
00085 isequal = GATFalse;
00086 retval = GATTable_Equals (a, b, &isequal);
00087 GAT_TEST (GAT_SUCCEEDED(retval));
00088 GAT_TEST (GATTrue == isequal);
00089 }
00090
00091
00092 GATSoftwareDescription_Destroy (&sw_desc2);
00093 GATSoftwareDescription_Destroy (&sw_desc1);
00094
00095 GATContext_Destroy (&context);
00096
00097 GAT_TEST_STOP ();
00098 GAT_TEST_FINISH ();
00099
00100 return 0;
00101 }
00102
00103
00104 static GATSoftwareDescription
00105 get_sw_description_direct(GATContext context, int argc, char *argv[])
00106 {
00107 GATSoftwareDescription sw_desc = NULL;
00108 GATLocation location = NULL;
00109 GATList_String arguments = NULL;
00110 GATTable environment = NULL;
00111 GATFile file = NULL;
00112 char *env_string = NULL;
00113 int i = 0;
00114 GATTable attributes = NULL;
00115
00116 GAT_TEST_START("get_sw_description_direct");
00117
00118
00119 attributes = GATTable_Create();
00120 GAT_TEST(NULL != attributes);
00121
00122
00123 location = GATLocation_Create(argv[0]);
00124 GAT_TEST(NULL != location);
00125
00126
00127 arguments = GATList_String_Create();
00128 GAT_TEST(NULL != arguments);
00129
00130 for (i = 1; i < argc; ++i)
00131 {
00132 int retval = (GATList_String_Insert(arguments,
00133 GATList_String_End(arguments), argv[i])) ?
00134 GAT_SUCCESS : GAT_MEMORYFAILURE;
00135 GAT_TEST(GAT_SUCCEEDED(retval));
00136 }
00137
00138
00139 environment = GATTable_Create();
00140 GAT_TEST(NULL != environment);
00141
00142 env_string = getenv("INCLUDE");
00143 if (NULL != env_string)
00144 {
00145 GATTable_Add_String(environment, "INCLUDE", env_string);
00146 }
00147 env_string = getenv("PATH");
00148 if (NULL != env_string)
00149 {
00150 GATTable_Add_String(environment, "PATH", env_string);
00151 }
00152 env_string = getenv("HOME");
00153 if (NULL != env_string)
00154 {
00155 GATTable_Add_String(environment, "HOME", env_string);
00156 }
00157
00158
00159 GATTable_Add_GATObject(attributes, "location",
00160 GATLocation_ToGATObject_const(location));
00161 GATTable_Add_GATObject(attributes, "arguments",
00162 GATList_String_ToGATObject_const(arguments));
00163 GATTable_Add_GATObject(attributes, "environment",
00164 GATTable_ToGATObject_const(environment));
00165
00166 file = create_gatfile(context, "stdin");
00167 GATTable_Add_GATObject(attributes, "stdin",
00168 GATFile_ToGATObject_const(file));
00169 GATFile_Destroy(&file);
00170
00171 file = create_gatfile(context, "stdout");
00172 GATTable_Add_GATObject(attributes, "stdout",
00173 GATFile_ToGATObject_const(file));
00174 GATFile_Destroy(&file);
00175
00176 file = create_gatfile(context, "stderr");
00177 GATTable_Add_GATObject(attributes, "stderr",
00178 GATFile_ToGATObject_const(file));
00179 GATFile_Destroy(&file);
00180
00181
00182 sw_desc = GATSoftwareDescription_Create(attributes);
00183 GAT_TEST(NULL != sw_desc);
00184
00185 test_sw_attributes(sw_desc, argc, argv);
00186
00187
00188 {
00189 GATSoftwareDescription sw_desc_clone = NULL;
00190 GATBool isequal = GATFalse;
00191 int retval = GAT_FAIL;
00192
00193 retval = GATSoftwareDescription_Clone(sw_desc, &sw_desc_clone);
00194 GAT_TEST(GAT_SUCCEEDED(retval) && NULL != sw_desc_clone);
00195
00196 retval = GATSoftwareDescription_Equals(sw_desc, sw_desc_clone, &isequal);
00197 GAT_TEST(GAT_SUCCEEDED(retval) && GATTrue == isequal);
00198 }
00199
00200 GATTable_Destroy(&environment);
00201 GATList_String_Destroy(&arguments);
00202 GATLocation_Destroy(&location);
00203 GATTable_Destroy(&attributes);
00204
00205 GAT_TEST_STOP ();
00206
00207 return sw_desc;
00208 }
00209
00210 static GATFile
00211 create_gatfile(GATContext context, char const *name)
00212 {
00213 GATLocation location = NULL;
00214 GATFile file = NULL;
00215
00216 GAT_TEST_START("create_gatfile");
00217
00218 location = GATLocation_Create(name);
00219 GAT_TEST(NULL != location);
00220
00221 file = GATFile_Create(context, location, 0);
00222 GAT_TEST(NULL != file);
00223
00224 GATLocation_Destroy(&location);
00225
00226 GAT_TEST_STOP ();
00227
00228 return file;
00229 }
00230
00231 static void
00232 test_sw_attributes(GATSoftwareDescription_const sw_desc, int argc, char *argv[])
00233 {
00234 GATResult retval = GAT_FAIL;
00235 GATBool isequal = GATFalse;
00236 GATType type = GATType_NoType;
00237 GATTable_const attributes = NULL;
00238
00239 GAT_TEST_START("test_sw_attributes");
00240
00241 attributes = GATSoftwareDescription_GetAttributes(sw_desc);
00242 GAT_TEST(NULL != attributes);
00243
00244
00245 {
00246 GATObject_const location = NULL;
00247 char *name = NULL;
00248
00249 retval = GATTable_Get_GATObject(attributes, "location", &location);
00250 type = GATObject_GetType(location);
00251 GAT_TEST(GAT_SUCCEEDED(retval) && NULL != location && GATType_GATLocation == type);
00252
00253 name = GATLocation_ToString(GATObject_ToGATLocation_const(location));
00254 GAT_TEST(NULL != name);
00255
00256 isequal = !strcmp(name, argv[0]) ? GATTrue : GATFalse;
00257 GAT_TEST(GATTrue == isequal);
00258
00259 free(name);
00260 }
00261
00262
00263 {
00264 GATObject_const arg_obj = NULL;
00265 GATList_String_const arguments = NULL;
00266 GATList_String_Iterator it = NULL;
00267 GATList_String_Iterator end = NULL;
00268 int i = 1;
00269
00270 retval = GATTable_Get_GATObject(attributes, "arguments", &arg_obj);
00271 type = GATObject_GetType(arg_obj);
00272 GAT_TEST(GAT_SUCCEEDED(retval) && NULL != arg_obj && GATType_GATList == type);
00273
00274 arguments = GATObject_ToGATList_String_const(arg_obj);
00275 GAT_TEST(NULL != arguments);
00276
00277 it = GATList_String_Begin(arguments);
00278 end = GATList_String_End(arguments);
00279 GAT_TEST(NULL != it && NULL != end);
00280
00281 for (; i < argc && it != end; ++i, it = GATList_String_Next(it))
00282 {
00283 char const *value = GATList_String_Get(it);
00284
00285 GAT_TEST(NULL != value);
00286
00287 isequal = !strcmp(value, argv[i]);
00288 GAT_TEST(GATTrue == isequal);
00289 }
00290 GAT_TEST(i == argc && it == end);
00291 }
00292
00293
00294 {
00295 GATObject_const env_obj = NULL;
00296 GATTable_const environment = NULL;
00297 char *env_string = NULL;
00298 char buffer[4096];
00299 int size = 0;
00300
00301 retval = GATTable_Get_GATObject(attributes, "environment", &env_obj);
00302 type = GATObject_GetType(env_obj);
00303 GAT_TEST(GAT_SUCCEEDED(retval) && NULL != env_obj && GATType_GATTable == type);
00304
00305 environment = GATObject_ToGATTable_const(env_obj);
00306 GAT_TEST(NULL != environment);
00307
00308 env_string = getenv("INCLUDE");
00309 if (NULL != env_string)
00310 {
00311 size = GATTable_Get_String(environment, "INCLUDE", buffer, sizeof(buffer));
00312 GAT_TEST(size > 0 && !strncmp(env_string, buffer, size));
00313 }
00314 env_string = getenv("PATH");
00315 if (NULL != env_string)
00316 {
00317 size = GATTable_Get_String(environment, "PATH", buffer, sizeof(buffer));
00318 GAT_TEST(size > 0 && !strncmp(env_string, buffer, size));
00319 }
00320 env_string = getenv("HOME");
00321 if (NULL != env_string)
00322 {
00323 size = GATTable_Get_String(environment, "HOME", buffer, sizeof(buffer));
00324 GAT_TEST(size > 0 && !strncmp(env_string, buffer, size));
00325 }
00326 }
00327
00328
00329 test_std_file_attriutes(attributes, "stdin");
00330 test_std_file_attriutes(attributes, "stdout");
00331 test_std_file_attriutes(attributes, "stderr");
00332
00333 GAT_TEST_STOP ();
00334 }
00335
00336 static void
00337 test_std_file_attriutes(GATTable_const attributes, char const *filename)
00338 {
00339 GATObject_const file_obj = NULL;
00340 GATType type = GATType_NoType;
00341 GATLocation_const location = NULL;
00342 GATResult retval = GAT_FAIL;
00343 char *name = NULL;
00344 GATBool isequal = GATFalse;
00345
00346 GAT_TEST_START("test_std_file_attriutes");
00347
00348 retval = GATTable_Get_GATObject(attributes, filename, &file_obj);
00349 type = GATObject_GetType(file_obj);
00350 GAT_TEST(GAT_SUCCEEDED(retval) && NULL != file_obj && GATType_GATFile == type);
00351
00352 location = GATFile_GetLocation(GATObject_ToGATFile_const(file_obj));
00353 GAT_TEST(NULL != location);
00354
00355 name = GATLocation_ToString(location);
00356 isequal = !strcmp(name, filename) ? GATTrue : GATFalse;
00357 GAT_TEST(GATTrue == isequal);
00358 free(name);
00359
00360 GAT_TEST_STOP ();
00361 }
00362