/Users/maurits/Documents/studie/afstuderen/biosphere/tests/test_definition_copy.c

Go to the documentation of this file.
00001 /*
00002  * Author: MA Hartman
00003  * Date: apr 12, 2007
00004  * 
00005  * Function:
00006  * Test program for libbiosphere.
00007  * 
00008  * License information:
00009  * 
00010  * Copyright (c) 2006 Maurits Hartman
00011  *
00012  * Permission is hereby granted, free of charge, to any person
00013  * obtaining a copy of this software and associated documentation
00014  * files (the "Software"), to deal in the Software without
00015  * restriction, including without limitation the rights to use,
00016  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00017  * copies of the Software, and to permit persons to whom the
00018  * Software is furnished to do so, subject to the following
00019  * conditions:
00020  * 
00021  * The above copyright notice and this permission notice shall be
00022  * included in all copies or substantial portions of the Software.
00023  * 
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00026  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00028  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00029  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00030  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00031  * OTHER DEALINGS IN THE SOFTWARE.
00032  * 
00033  */
00034 
00035 #include <biosphere_lib.h>
00036 #include <type.h>
00037 
00038 #include <apr_pools.h>
00039 #include <apr_strings.h>
00040 
00041 
00042 int main(int argc, char *argv[])
00043 {
00044         int exit_code = 0;
00045         apr_pool_t *mp;
00046         bs_definition *def, *cpy;
00047         bs_data_type *dt1, *dt2;
00048         bs_message_part *part1, *part2;
00049         bs_message *msg1, *msg2;
00050         bs_port_type *pt;
00051         bs_operation *op;
00052         bs_port *port;
00053         bs_service *svc;
00054         
00055         apr_initialize();
00056         apr_pool_create(&mp, NULL);
00057 
00058         /* Set up definition: */
00059         def = new_bs_definition(mp, "definition", 4, 2, 1, 1);
00060         dt1 = new_bs_data_type(mp, "data_type1");
00061         dt2 = new_bs_data_type(mp, "data_type2");
00062         def->data_types[0] = dt1;
00063         def->data_types[1] = dt2;
00064         
00065         part1 = new_bs_message_part(mp, "part1", dt1);
00066         part2 = new_bs_message_part(mp, "part2", dt2);
00067         msg1 = new_bs_message(mp, "message1", 2);
00068         msg1->parts[0] = part1;
00069         msg1->parts[1] = part2;
00070         def->messages[0] = msg1;
00071         
00072         dt1 = new_bs_data_type(mp, "data_type3");
00073         dt2 = new_bs_data_type(mp, "data_type4");
00074         def->data_types[2] = dt1;
00075         def->data_types[3] = dt2;
00076         part1 = new_bs_message_part(mp, "part3", dt1);
00077         part2 = new_bs_message_part(mp, "part4", dt2);
00078         msg2 = new_bs_message(mp, "message2", 2);
00079         msg2->parts[0] = part1;
00080         msg2->parts[1] = part2;
00081         def->messages[1] = msg2;
00082         
00083         op = new_bs_operation(mp, "operation1", msg1, msg2, NULL);
00084         pt = new_bs_port_type(mp, "port_type1", 1);
00085         pt->operations[0] = op;
00086         def->port_types[0] = pt;
00087         port = new_bs_port(mp, "port1", pt);
00088         svc = new_bs_service(mp, "service1", 1);
00089         svc->ports[0] = port;
00090         def->services[0] = svc;
00091         
00092         /* Make a copy: */
00093         cpy = copy_bs_definition(def);
00094         
00095         /* Check if it's correct: */
00096         if (cpy->num_data_types != 4) exit_code = 1;
00097         else if (cpy->num_messages != 2) exit_code = 2;
00098         else if (cpy->num_port_types != 1) exit_code = 3;
00099         else if (cpy->num_services != 1) exit_code = 4;
00100         else if (apr_strnatcmp(cpy->data_types[0]->name, "data_type1") != 0) exit_code = 5;
00101         else if (apr_strnatcmp(cpy->data_types[1]->name, "data_type2") != 0) exit_code = 6;
00102         else if (apr_strnatcmp(cpy->data_types[2]->name, "data_type3") != 0) exit_code = 7;
00103         else if (apr_strnatcmp(cpy->data_types[3]->name, "data_type4") != 0) exit_code = 8;
00104         else if (apr_strnatcmp(cpy->messages[0]->name, "message1") != 0) exit_code = 9;
00105         else if (apr_strnatcmp(cpy->messages[0]->parts[0]->name, "part1") != 0) exit_code = 10;
00106         else if (apr_strnatcmp(cpy->messages[0]->parts[1]->name, "part2") != 0) exit_code = 11;
00107         else if (apr_strnatcmp(cpy->messages[1]->name, "message2") != 0) exit_code = 12;
00108         else if (apr_strnatcmp(cpy->messages[1]->parts[0]->name, "part3") != 0) exit_code = 13;
00109         else if (apr_strnatcmp(cpy->messages[1]->parts[1]->name, "part4") != 0) exit_code = 14;
00110         else if (apr_strnatcmp(cpy->port_types[0]->name, "port_type1") != 0) exit_code = 15;
00111         else if (apr_strnatcmp(cpy->port_types[0]->operations[0]->name, "operation1") != 0) exit_code = 16;
00112         else if (apr_strnatcmp(cpy->port_types[0]->operations[0]->input->name, "message1") != 0) exit_code = 17;
00113         else if (apr_strnatcmp(cpy->port_types[0]->operations[0]->output->name, "message2") != 0) exit_code = 18;
00114         else if (apr_strnatcmp(cpy->services[0]->name, "service1") != 0) exit_code = 19;
00115         else if (apr_strnatcmp(cpy->services[0]->ports[0]->name, "port1") != 0) exit_code = 20;
00116         else if (apr_strnatcmp(cpy->services[0]->ports[0]->port_type->name, "port_type1") != 0) exit_code = 21;
00117         
00118         delete_bs_definition(cpy);
00119         apr_pool_destroy(mp);
00120         apr_terminate();
00121         return exit_code;
00122 }

Generated on Tue Jul 17 09:50:53 2007 for Bio-SPHERE by  doxygen 1.5.1