/* test_comc.cc - Programme de test du comc. */ /* Simulotron - Programme de simulation de robot {{{ * * Copyright (C) 2006 Nicolas Haller * * Robot APB Team/Efrei 2005. * Web: http://assos.efrei.fr/robot/ * Email: robot AT efrei DOT fr * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ #include "comc/struct_message.hh" #include "comc/comc.hh" #include "socket/socket_server.hh" #include #include // message de test msg0 ms; int testGSServer(SocketServer & sockServ); void testGSClient(int pauseMode); int main(void) { //pauseMode pour debbuger le fork int pauseMode = 0; int pid; //retour des test int resultClient, resultServer; //Initialisation des valeurs de la struct de test ms.i = 42; ms.d = 23.23; ms.strh = "chier!!!"; ms.s = 4; ms.str = "Ho!! Une structure de test, comme c'est amusant!!"; ms.l = 3432; // Création de la socket serveur; SocketServer sockServ(std::string(),4242); // Mise en écoute du socket serveur sockServ.listen(12); // On crée le fork du client pid = fork(); if (pid == 0) // processus fils testGSClient(pauseMode); else //processus père resultServer = testGSServer(sockServ); // On analyse les résultats wait(&resultClient); if (!(WIFEXITED(resultClient) && WEXITSTATUS(resultClient) == 0)) { std::cerr << "ECHEC: Problème coté client" << std::endl; exit (-1); } if (resultServer != 0) { std::cerr << "ECHEC: Problème coté serveur" << std::endl; exit (-1); } return 0; } int testGSServer(SocketServer & sockServ) { try { std::string source, dest; GSMessage gsm; msg0 mscom; int msgId; // Création de la comc ComC comc(sockServ,"serveur"); while(!comc.receiveGS(gsm,source,dest, msgId, true)){} mscom.gsToMsg(gsm); if(!(ms.i == mscom.i && ms.d == mscom.d && ms.strh == mscom.strh && ms.s == mscom.s && ms.str == mscom.str && ms.l == mscom.l)) { std::cout << "CHIER!! Le message recu n'est pas identique !!" << std::endl; std::cout << "m d'origine: " << ms.i << "\nm d'arrivée: " << mscom.i << "result: " << (ms.i == mscom.i) << std::endl; std::cout << "m d'origine: " << ms.d << "\nm d'arrivée: " << mscom.d << "result: " << (ms.d == mscom.d) << std::endl; std::cout << "m d'origine: " << ms.strh << "\nm d'arrivée: " << mscom.strh << "result: " << (ms.strh == mscom.strh) << std::endl; std::cout << "m d'origine: " << ms.s << "\nm d'arrivée: " << mscom.s << "result: " << (ms.s == mscom.s) << std::endl; std::cout << "m d'origine: " << ms.str << "\nm d'arrivée: " << mscom.str << "result: " << (ms.str == mscom.str) << std::endl; std::cout << "m d'origine: " << ms.l << "\nm d'arrivée: " << mscom.l << "result: " << (ms.l == mscom.l) << std::endl; return 1; } } catch (std::exception & c) { std::cout << "Oops, exeption dans le serveur" << std::endl; } return 0; } void testGSClient(int pauseMode) { while(pauseMode) sleep (10); try { // Création du comc ComC comc(std::string("127.0.0.1"), 4242, "client"); comc.send(ms, std::string("serveur")); } catch(std::exception & chier) { std::cout << "CHIER !! Une exception a été lancé coté client!!" << std::endl; std::cout << chier.what() << std::endl; exit (1); } exit (0); }