Exemplo n.º 1
0
   void LER_ExibirParametro( char * Simbolo )
   {

      tpElemSimbolo * pElem ;

      #ifdef _DEBUG
         TST_ASSERT( Inicializado ) ;
      #endif

      pElem = ( tpElemSimbolo * ) TBS_ProcurarSimbolo( pTabela , Simbolo ) ;

      if ( pElem == NULL )
      {
         TST_ExibirPrefixo( INFO_LER , "Parâmetro não definido: " ) ;
         fprintf( TST_ObterArqLog( ) , "%s" , Simbolo ) ;
         return ;
      } /* if */

      TST_ExibirPrefixo( INFO_LER , "Parâmetro: " ) ;
      fprintf( TST_ObterArqLog( ) , "%s" , Simbolo ) ;
      TST_ExibirEspacoHexa( sizeof( tpElemSimbolo ) , pElem ) ;

      if ( ( pElem->idTipo == ID_TIPO_STRING )
        || ( pElem->idTipo == ID_TIPO_NOME ))
      {
         TST_ExibirEspacoHexa( strlen( pElem->ValorTipado.ValorString ) + 1 ,
                                       pElem->ValorTipado.ValorString ) ;
      } /* if */

   } /* Fim função: LER  &Exibir declaração de símbolo */
Exemplo n.º 2
0
   tpElemSimbolo * ObterDado( char idTipo )
   {

      char Nome[ LER_DIM_NOME ] ;

      tpElemSimbolo * pElem = NULL ;

      int tamNome ;

      if ( LER_LerParmNome( Nome , &tamNome , LER_DIM_NOME ) == FALSE )
      {
         ExibirErro( "Sintaxe errada para nome de parâmetro." ) ;
         return NULL ;
      } /* if */

      pElem = ( tpElemSimbolo * ) TBS_ProcurarSimbolo( pTabela , Nome ) ;

      if ( pElem == NULL )
      {
         ExibirErro( "Parâmetro não está definido: " ) ;
         fprintf( TST_ObterArqLog( ) , "%s" , Nome ) ;
         return NULL ;
      } /* if */

      if ( pElem->idTipo != idTipo )
      {
         ExibirErro( "Tipo do parâmetro incorreto. " ) ;
         fprintf( TST_ObterArqLog( ) , "%s" , Nome ) ;
         return NULL ;
      } /* if */

      return pElem ;

   } /* Fim função: LER  -Obter dado associado a parâmetro simbólico */
Exemplo n.º 3
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int inxTabela  = -1 ,
          idTipo     = -1 ,
          numLidos   = -1 ,
          CondRetEsp = -1  ;

      TST_tpCondRet CondRet ;

      char StringDado[  DIM_SIMB ] ;
      char StringValor[ DIM_SIMB ] ;

      int i ;

      int tamTabela = -1 ;

      int ValInt = -1 ;

      tpTipo1 * pDado1 ;

      char ValChar = '\0' ;

      tpTipo2 * pDado2 ;

      tpTipo3 * pDado3 ;

      int ValIntEsp = -1 ;

      char ValCharEsp = '*' ;

      StringDado[ 0 ] = 0 ;

      /* Efetuar reset de teste de tabela */

         if ( strcmp( ComandoTeste , RESET_TAB_CMD ) == 0 )
         {

            for( i = 0 ; i < DIM_VT_TABELAS ; i++ )
            {
               vtTabelas[ i ] = NULL ;
            } /* for */

            return TST_CondRetOK ;

         } /* fim ativa: Efetuar reset de teste de tabela */

      /* Testar CriarTabela */

         else if ( strcmp( ComandoTeste , CRIAR_TAB_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iii" ,
                       &inxTabela , &tamTabela , &idTipo ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxTabela( inxTabela , VAZIO ))
              || ( ! ValidarIdTipo( idTipo ))
              || ( tamTabela <= 1 ))
            {
               return TST_CondRetParm ;
            } /* if */

            if ( idTipo == ID_TIPO_1 )
            {
               vtTabelas[ inxTabela ] =
                    TBS_CriarTabela( tamTabela , ObterSimboloTipoUm , NULL ) ;
            } else if ( idTipo == ID_TIPO_2 )
            {
               vtTabelas[ inxTabela ] =
                    TBS_CriarTabela( tamTabela , ObterSimboloTipoDois , NULL ) ;
            } else
            {
               vtTabelas[ inxTabela ] =
                    TBS_CriarTabela( tamTabela , ObterSimboloTipoTres ,
                                                 LiberarDadoTipoTres    ) ;
            } /* if */

            return TST_CompararPonteiroNulo( 1 , vtTabelas[ inxTabela ] ,
               "Erro em ponteiro de nova tabela."  ) ;

         } /* fim ativa: Testar CriarTabela */

      /* Testar Destruir tabela */

         else if ( strcmp( ComandoTeste , DESTRUIR_TAB_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                               &inxTabela ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            TBS_DestruirTabela( vtTabelas[ inxTabela ] ) ;
            vtTabelas[ inxTabela ] = NULL ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Destruir tabela */

      /* Testar Inserir simbolo tipo um */

         else if ( strcmp( ComandoTeste , INS_SIMB_UM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iisi" ,
                       &inxTabela , &ValInt , StringDado , &CondRetEsp ) ;

            if ( ( numLidos != 4 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado1 = ( tpTipo1 * ) malloc( sizeof( tpTipo1 )) ;
            if ( pDado1 == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            pDado1->Conta   = ValInt ;
            strcpy( pDado1->SimboloUm , StringDado ) ;


            CondRet = (TST_tpCondRet) TBS_InserirSimbolo( vtTabelas[ inxTabela ] , pDado1 ) ;

            if ( CondRet != TBS_CondRetOK )
            {
               free( pDado1 ) ;
            } /* if */

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condição de retorno errada em símbolo tipo um."                   ) ;

         } /* fim ativa: Testar Inserir simbolo tipo um */

      /* Testar Inserir simbolo tipo dois */

         else if ( strcmp( ComandoTeste , INS_SIMB_DOIS_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "icsi" ,
                       &inxTabela , &ValChar , StringDado , &CondRetEsp ) ;

            if ( ( numLidos != 4 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado2 = ( tpTipo2 * ) malloc( sizeof( tpTipo2 )) ;
            if ( pDado2 == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */
            pDado2->Id   = ValChar ;
            strcpy( pDado2->SimboloDois , StringDado ) ;

            return TST_CompararInt( CondRetEsp ,
                          TBS_InserirSimbolo( vtTabelas[ inxTabela ] , pDado2 ) ,
                     "Condição de retorno errada em símbolo tipo dois."                   ) ;

         } /* fim ativa: Testar Inserir simbolo tipo dois */

      /* Testar Inserir simbolo tipo tres */

         else if ( strcmp( ComandoTeste , INS_SIMB_TRES_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "issi" ,
                       &inxTabela , StringDado , StringValor , &CondRetEsp ) ;

            if ( ( numLidos != 4 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado3 = ( tpTipo3 * ) malloc( sizeof( tpTipo3 )) ;
            if ( pDado3 == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            pDado3->pString = (char*) malloc( strlen( StringValor ) + 1 ) ;
            strcpy( pDado3->pString , StringValor ) ;

            strcpy( pDado3->SimboloTres , StringDado ) ;

            return TST_CompararInt( CondRetEsp ,
                          TBS_InserirSimbolo( vtTabelas[ inxTabela ] , pDado3 ) ,
                     "Condição de retorno errada em símbolo tipo dois."                   ) ;

         } /* fim ativa: Testar Inserir simbolo tipo tres */

      /* Testar excluir simbolo */

         else if ( strcmp( ComandoTeste , EXC_SIMB_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( (char*)  "isi" ,
                  (char*) &inxTabela , (char*) StringDado , (char*) &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp ,
                      TBS_ExcluirSimbolo( vtTabelas[ inxTabela ] , StringDado ) ,
                     "Condição de retorno errada ao excluir."                   ) ;

         } /* fim ativa: Testar excluir simbolo */

      /* Testar procurar símbolo tipo 1 */

         else if ( strcmp( ComandoTeste , PROCURAR_SIMB_UM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "isi" ,
                       &inxTabela , StringDado , &ValIntEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado1 = ( tpTipo1 * ) TBS_ProcurarSimbolo( vtTabelas[ inxTabela ] ,
                                            StringDado ) ;
            if ( ValIntEsp == -1 )
            {
               return TST_CompararPonteiroNulo( 0 , pDado1 ,
                         "Dado tipo um não deveria existir." ) ;
            } /* if */

            if ( pDado1 == NULL )
            {
               return TST_CompararPonteiroNulo( 1 , pDado1 ,
                         "Dado tipo um deveria existir." ) ;
            } /* if */

            return TST_CompararInt( ValIntEsp , pDado1->Conta ,
                         "Valor tipo um errado." ) ;

         } /* fim ativa: Testar procurar símbolo tipo 1 */

      /* Testar procurar símbolo tipo 2 */

         else if ( strcmp( ComandoTeste , PROCURAR_SIMB_DOIS_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "isc" ,
                       &inxTabela , StringDado , &ValCharEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado2 = ( tpTipo2 * ) TBS_ProcurarSimbolo( vtTabelas[ inxTabela ] ,
                                            StringDado ) ;
            if ( ValCharEsp == '*' )
            {
               return TST_CompararPonteiroNulo( 0 , pDado2 ,
                         "Dado tipo dois não deveria existir." ) ;
            } /* if */

            if ( pDado2 == NULL )
            {
               return TST_CompararPonteiroNulo( 1 , pDado2 ,
                         "Dado tipo dois deveria existir." ) ;
            } /* if */

            return TST_CompararChar( ValCharEsp , pDado2->Id ,
                         "Valor tipo dois errado." ) ;

         } /* fim ativa: Testar procurar símbolo tipo 2 */

      /* Testar procurar símbolo tipo 3 */

         else if ( strcmp( ComandoTeste , PROCURAR_SIMB_TRES_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iss" ,
                       &inxTabela , StringDado , StringValor ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado3 = ( tpTipo3 * ) TBS_ProcurarSimbolo( vtTabelas[ inxTabela ] ,
                                            StringDado ) ;

            if ( pDado3 == NULL )
            {
               return TST_CompararPonteiroNulo( 1 , pDado3 ,
                         "Dado tipo três deveria existir." ) ;
            } /* if */

            return TST_CompararString( StringValor , pDado3->pString ,
                         "Valor tipo três errado." ) ;

         } /* fim ativa: Testar procurar símbolo tipo 3 */

      /* Testar validar Tabela de símbolos */
      #ifdef _DEBUG

         else if ( strcmp( ComandoTeste , VALIDAR_TAB_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                               &inxTabela ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            return TBS_ValidarTabela( vtTabelas[ inxTabela ] ) ;

         } /* fim ativa: Testar validar Tabela de símbolos */
      #endif

      return TST_CondRetNaoConhec ;

   } /* Fim função: TTBS &Testar tabela de símbolos */
Exemplo n.º 4
0
   int LER_DeclararParametro( void )
   {

      char NomeDeclarado[ LER_DIM_NOME ] ;

      tpElemSimbolo * pElem = NULL ;

      int tamNome ;

      char NomeTipo[ DIM_TIPO ] ;

      int   tamString ;
      char  valString[ LER_DIM_STRING ] ;

      #ifdef _DEBUG
         TST_ASSERT( Inicializado ) ;
      #endif

      LER_InxBuffer = 0 ;

      /* Criar declaração de parâmetro */

         LER_PularComando( ) ;

         if ( LER_LerParmNome( NomeDeclarado , &tamNome , LER_DIM_NOME ) == FALSE )
         {
            ExibirErro( "Nome a declarar está errado." ) ;
            return FALSE ;
         } /* if */

         if ( TBS_ProcurarSimbolo( pTabela, NomeDeclarado ) != NULL )
         {
            ExibirErro( "Nome já foi declarado antes:" ) ;
            fprintf( TST_ObterArqLog( ) , " %s" , NomeDeclarado ) ;
            return FALSE ;
         } /* if */

         pElem = ( tpElemSimbolo * ) malloc( sizeof( tpElemSimbolo )) ;
         memset( pElem , 0 , sizeof( tpElemSimbolo )) ;

         if ( pElem == NULL )
         {
            ExibirErro( "Faltou memória." ) ;
            fprintf( TST_ObterArqLog( ) , " %s" , NomeDeclarado ) ;
            return FALSE ;
         } /* if */

         strcpy( pElem->Nome , NomeDeclarado ) ;

      /* Inserir tipo e valor */

         if ( LER_LerParmNome( NomeTipo , &tamNome , DIM_TIPO ) == FALSE )
         {
            ExibirErro( "Nome de tipo incorreto." ) ;
            free( pElem ) ;
            return FALSE ;
         } /* if */

         /* Inserir char */

            if ( strcmp( NomeTipo , NOME_TIPO_CHAR ) == 0 )
            {

               pElem->idTipo = ID_TIPO_CHAR ;
               if ( LER_LerParmChar( &( pElem->ValorTipado.ValorChar ) ) == FALSE )
               {
                  free( pElem ) ;
                  return FALSE ;
               } /* if */

            } /* fim ativa: Inserir char */

         /* Inserir inteiro */

            else if ( strcmp( NomeTipo , NOME_TIPO_INT ) == 0 )
            {

               pElem->idTipo = ID_TIPO_INT ;
               if ( LER_LerParmInt( &( pElem->ValorTipado.ValorInt ) ) == FALSE )
               {
                  free( pElem ) ;
                  return FALSE ;
               } /* if */

            } /* fim ativa: Inserir inteiro */

         /* Inserir double */

            else if ( strcmp( NomeTipo , NOME_TIPO_DOUBLE ) == 0 )
            {

               pElem->idTipo = ID_TIPO_DOUBLE ;
               if ( LER_LerParmDouble( &( pElem->ValorTipado.ValorDouble ) ) == FALSE )
               {
                  free( pElem ) ;
                  return FALSE ;
               } /* if */

            } /* fim ativa: Inserir double */

         /* Inserir string */

            else if ( strcmp( NomeTipo , NOME_TIPO_STRING ) == 0 )
            {

               pElem->idTipo = ID_TIPO_STRING ;
               if ( LER_LerParmString( valString , &tamString , LER_DIM_STRING ) == FALSE )
               {
                  free( pElem ) ;
                  return FALSE ;
               } /* if */
               pElem->ValorTipado.ValorString = ( char * ) malloc( tamString + 1 ) ;
               pElem->tamString               = tamString ;
               memcpy( pElem->ValorTipado.ValorString , valString , tamString + 1 ) ;

            } /* fim ativa: Inserir string */

         /* Tratar erro tipo desconhecido */

            else
            {

               ExibirErro( "Tipo de parâmetro desconhecido." ) ;
               free( pElem ) ;
               return FALSE ;

            } /* fim ativa: Tratar erro tipo desconhecido */

      /* Inserir declaração na tabela */

         if ( TBS_InserirSimbolo( pTabela, pElem ) != TBS_CondRetOK )
         {
            ExibirErro( "Ocorreu erro ao inserir símbolo na tabela." ) ;
            free( pElem ) ;
            return FALSE ;
         } /* if */

         return TRUE ;

   } /* Fim função: LER  &Declarar parâmetro simbólico */