Révision 109
Ajouté par yoguer il y a environ 4 ans
branch/Guer/sp4a12/main.c | ||
---|---|---|
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include "trame.h"
|
||
|
||
int decode_int(char c)
|
||
{
|
||
int a=0;
|
||
|
||
if(c>=48 && c<=57) //v?rifie que le caract?re est entre 0 et 9 compris
|
||
{
|
||
a=c-48; //donne la valeure en d?cimal du code ascii
|
||
}
|
||
else
|
||
{
|
||
a=-1; //renvoie -1 si autres caract?res que 0 ? 9
|
||
}
|
||
return a;
|
||
}
|
||
|
||
|
||
//Trames de tests ? modifier si n?cessaire.
|
||
char * trames[]= {"$GPGSV,3,2,10,15,03,077,,18,04,041,42,19,85,271,,20,08,214,*7C",
|
||
... | ... | |
|
||
if (trame_cmp(trame,"GPGGA")==1)
|
||
{
|
||
printf ("> %s\n",trame);
|
||
//printf ("> %s\n",trame);
|
||
}
|
||
}
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void)
|
||
{
|
||
if (5!=5)
|
||
{
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if (trame_cmp("$GPGGA suite chaine","GPGGA")==0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC suite chaine","GPGGA")==1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC... ", "GPRMC" )==0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$APRMC...", "GPGGA")==1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
||
... | ... | |
}
|
||
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void)
|
||
{
|
||
if (5!=5)
|
||
{
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if (trame_cmp("$GPGGA suite chaine","GPGGA")==0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC suite chaine","GPGGA")==1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$GPRMC... ", "GPRMC" )==0){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
if (trame_cmp("$APRMC...", "GPGGA")==1){
|
||
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
test_decode_int(); //test la fonction decode_int
|
||
}
|
||
|
||
|
||
void test_decode_int(void)
|
||
{
|
||
char i;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if (decode_int('i')==i);
|
||
{
|
||
printf("GOOD pour le caractere: %hd\n",i); //test si la fonction renvoie bien la bonne valeur d?cimal
|
||
}
|
||
}
|
||
|
||
if(decode_int('A')==-1)
|
||
{
|
||
printf("GOOD pour le caractere A\n"); //test si la fonction renvoie -1 pour le caract?re A
|
||
}
|
||
}
|
Formats disponibles : Unified diff
Test la fonction decode_int