LTP GCOV extension - code coverage report
Current view: directory - test/cpp/unit/cdr/read - TestCdrRead.cpp
Test: YAORB-0.2.info
Date: 2006-02-27 Instrumented lines: 212
Code covered: 81.6 % Executed lines: 173

       1                 : //==============================================================================
       2                 : // File <$/test/cpp/unit/cdr/read/TestCdrRead.cpp>
       3                 : // This file is part of YaOrb : Yet Another Object Request Broker,
       4                 : // Copyright (c) 2000-2003, Marc Alff.
       5                 : //
       6                 : // This program is free software; you can redistribute it and/or
       7                 : // modify it under the terms of the GNU General Public License
       8                 : // as published by the Free Software Foundation; either version 2
       9                 : // of the License, or (at your option) any later version.
      10                 : //
      11                 : // This program is distributed in the hope that it will be useful,
      12                 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 : // GNU General Public License for more details.
      15                 : //
      16                 : // You should have received a copy of the GNU General Public License
      17                 : // along with this program; if not, write to the Free Software
      18                 : // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
      19                 : //
      20                 : //==============================================================================
      21                 : 
      22                 : #include "yaorb/CORBA.h"
      23                 : #include "yaorb/YAORB.h"
      24                 : #include "src/cpp/prod/tool/String.h"
      25                 : #include "src/cpp/prod/protocol/cdr/cdr_file.h"
      26                 : 
      27                 : void
      28              20 : PrintBool(FILE *output, CORBA::Boolean b)
      29                 : {
      30                 :    const char* str = "TRUE" ;
      31                 : 
      32              20 :    if (b == false)
      33                 :    {
      34                 :       str = "FALSE" ;
      35                 :    }
      36                 : 
      37              20 :    fprintf(output, "Boolean:%s\n", str) ;
      38                 : }
      39                 : 
      40                 : void
      41               2 : TestBool(YAORB::CDR *cdr, FILE *output)
      42                 : {
      43                 :    CORBA::Boolean b ;
      44                 :    CORBA::Boolean bArray[8] ;
      45                 :    int size = 8 ;
      46                 :    int i ;
      47                 : 
      48                 :    // Expecting to read :
      49                 :    // 1 + 1 + 8 = 10 Boolean
      50                 :    // 10 bytes total.
      51                 : 
      52               2 :    b = false ;
      53               2 :    cdr->cdr_Boolean(& b) ;
      54               2 :    PrintBool(output, b) ;
      55                 : 
      56               2 :    b = false ;
      57               2 :    cdr->cdr_Boolean(& b) ;
      58               2 :    PrintBool(output, b) ;
      59                 : 
      60                 : #ifdef LATER
      61                 :    // Expecting to read True = 1 or throw marshall ?
      62                 :    b = false ;
      63                 :    cdr->cdr_Boolean(& b) ;
      64                 :    PrintBool(output, b) ;
      65                 : #endif
      66                 : 
      67              16 :    for (i = 0 ; i < size ; i++)
      68                 :    {
      69              16 :       bArray[i] = false ;
      70                 :    }
      71                 : 
      72               2 :    cdr->cdr_BooleanArray(& bArray[0], size) ;
      73                 : 
      74              16 :    for (i = 0 ; i < size ; i++)
      75                 :    {
      76              16 :       PrintBool(output, bArray[i]) ;
      77                 :    }
      78                 : 
      79                 :    return ;
      80                 : }
      81                 : 
      82                 : void
      83              14 : PrintOctet(FILE *output, CORBA::Octet o)
      84                 : {
      85              14 :    fprintf(output, "Octet:0x%02x\n", o) ;
      86                 : }
      87                 : 
      88                 : void
      89               2 : TestOctet(YAORB::CDR *cdr, FILE *output)
      90                 : {
      91                 :    CORBA::Octet o ;
      92                 :    CORBA::Octet oArray[5] ;
      93                 : 
      94                 :    // Expecting to read :
      95                 :    // 1 + 1 + 5 = 7 Octet
      96                 :    // 7 bytes total.
      97                 : 
      98               2 :    o = 0 ;
      99               2 :    cdr->cdr_Octet(& o) ;
     100               2 :    PrintOctet(output, o) ;
     101                 : 
     102               2 :    o = 0 ;
     103               2 :    cdr->cdr_Octet(& o) ;
     104               2 :    PrintOctet(output, o) ;
     105                 : 
     106               2 :    oArray[0] = 0 ;
     107               2 :    oArray[1] = 0 ;
     108               2 :    oArray[2] = 0 ;
     109               2 :    oArray[3] = 0 ;
     110               2 :    oArray[4] = 0 ;
     111                 : 
     112               2 :    cdr->cdr_OctetArray(& oArray[0], 5) ;
     113                 : 
     114              10 :    for (int i=0 ; i < 5 ; i++)
     115                 :    {
     116              10 :       PrintOctet(output, oArray[i]) ;
     117                 :    }
     118                 : }
     119                 : 
     120                 : void
     121              12 : PrintChar(FILE *output, CORBA::Char c)
     122                 : {
     123              12 :    fprintf(output, "Char:\'%c\'\n", c) ;
     124                 : }
     125                 : 
     126                 : void
     127               2 : TestChar(YAORB::CDR *cdr, FILE *output)
     128                 : {
     129                 :    CORBA::Char c ;
     130                 :    CORBA::Char cArray[4] ;
     131                 : 
     132                 :    // Expecting to read :
     133                 :    // 1 + 1 + 4 = 6 Char
     134                 :    // 6 bytes total.
     135                 : 
     136               2 :    c = '*' ;
     137               2 :    cdr->cdr_Char(& c) ;
     138               2 :    PrintChar(output, c) ;
     139                 : 
     140               2 :    c = '*' ;
     141               2 :    cdr->cdr_Char(& c) ;
     142               2 :    PrintChar(output, c) ;
     143                 : 
     144               2 :    cArray[0] = '*' ;
     145               2 :    cArray[1] = '*' ;
     146               2 :    cArray[2] = '*' ;
     147               2 :    cArray[3] = '*' ;
     148                 : 
     149               2 :    cdr->cdr_CharArray(& cArray[0], 4) ;
     150                 : 
     151               8 :    for (int i=0 ; i < 4 ; i++)
     152                 :    {
     153               8 :       PrintChar(output, cArray[i]) ;
     154                 :    }
     155                 : }
     156                 : 
     157                 : void
     158               0 : TestWChar(YAORB::CDR *cdr, FILE *output)
     159                 : {
     160                 : }
     161                 : 
     162                 : void
     163              10 : PrintShort(FILE *output, CORBA::Short s)
     164                 : {
     165              10 :    if (s >= 0)
     166                 :    {
     167               6 :       fprintf(output, "Short:0x%04x\n", s) ;
     168                 :    }
     169                 :    else
     170                 :    {
     171               4 :       fprintf(output, "Short:-0x%04x\n", -s) ;
     172                 :    }
     173                 : }
     174                 : 
     175                 : void
     176               2 : TestShort(YAORB::CDR *cdr, FILE *output)
     177                 : {
     178                 :    CORBA::Short s ;
     179                 :    CORBA::Short sArray[3] ;
     180                 : 
     181                 :    // Expecting to read :
     182                 :    // 1 + 1 + 3 = 5 Short
     183                 :    // 10 bytes total.
     184                 : 
     185               2 :    s = 0 ;
     186               2 :    cdr->cdr_Short(& s) ;
     187               2 :    PrintShort(output, s) ;
     188                 : 
     189               2 :    s = 0 ;
     190               2 :    cdr->cdr_Short(& s) ;
     191               2 :    PrintShort(output, s) ;
     192                 : 
     193               2 :    sArray[0] = 0 ;
     194               2 :    sArray[1] = 0 ;
     195               2 :    sArray[2] = 0 ;
     196                 : 
     197               2 :    cdr->cdr_ShortArray(& sArray[0], 3) ;
     198                 : 
     199               6 :    for (int i=0 ; i < 3 ; i++)
     200                 :    {
     201               6 :       PrintShort(output, sArray[i]) ;
     202                 :    }
     203                 : }
     204                 : 
     205                 : void
     206              10 : PrintUShort(FILE *output, CORBA::UShort s)
     207                 : {
     208              10 :    fprintf(output, "UShort:0x%04x\n", s) ;
     209                 : }
     210                 : 
     211                 : void
     212               2 : TestUShort(YAORB::CDR *cdr, FILE *output)
     213                 : {
     214                 :    CORBA::UShort us ;
     215                 :    CORBA::UShort usArray[3] ;
     216                 : 
     217                 :    // Expecting to read :
     218                 :    // 1 + 1 + 3 = 5 UShort
     219                 :    // 10 bytes total.
     220                 : 
     221               2 :    us = 0 ;
     222               2 :    cdr->cdr_UShort(& us) ;
     223               2 :    PrintUShort(output, us) ;
     224                 : 
     225               2 :    us = 0 ;
     226               2 :    cdr->cdr_UShort(& us) ;
     227               2 :    PrintUShort(output, us) ;
     228                 : 
     229               2 :    usArray[0] = 0 ;
     230               2 :    usArray[1] = 0 ;
     231               2 :    usArray[2] = 0 ;
     232                 : 
     233               2 :    cdr->cdr_UShortArray(& usArray[0], 3) ;
     234                 : 
     235               6 :    for (int i=0 ; i < 3 ; i++)
     236                 :    {
     237               6 :       PrintUShort(output, usArray[i]) ;
     238                 :    }
     239                 : }
     240                 : 
     241                 : void
     242              10 : PrintLong(FILE *output, CORBA::Long l)
     243                 : {
     244              10 :    if (l >= 0)
     245                 :    {
     246               6 :       fprintf(output, "Long:0x%08x\n", l) ;
     247                 :    }
     248                 :    else
     249                 :    {
     250               4 :       fprintf(output, "Long:-0x%08x\n", -l) ;
     251                 :    }
     252                 : }
     253                 : 
     254                 : void
     255               2 : TestLong(YAORB::CDR *cdr, FILE *output)
     256                 : {
     257                 :    CORBA::Long l ;
     258                 :    CORBA::Long lArray[3] ;
     259                 : 
     260                 :    // Expecting to read :
     261                 :    // 1 + 1 + 3 = 5 Long
     262                 :    // 20 bytes total.
     263                 : 
     264               2 :    l = 0 ;
     265               2 :    cdr->cdr_Long(& l) ;
     266               2 :    PrintLong(output, l) ;
     267                 : 
     268               2 :    l = 0 ;
     269               2 :    cdr->cdr_Long(& l) ;
     270               2 :    PrintLong(output, l) ;
     271                 : 
     272               2 :    lArray[0] = 0 ;
     273               2 :    lArray[1] = 0 ;
     274               2 :    lArray[2] = 0 ;
     275                 : 
     276               2 :    cdr->cdr_LongArray(& lArray[0], 3) ;
     277                 : 
     278               2 :    PrintLong(output, lArray[0]) ;
     279               2 :    PrintLong(output, lArray[1]) ;
     280               2 :    PrintLong(output, lArray[2]) ;
     281                 : }
     282                 : 
     283                 : void
     284              10 : PrintULong(FILE *output, CORBA::ULong ul)
     285                 : {
     286              10 :    fprintf(output, "ULong:0x%08x\n", ul) ;
     287                 : }
     288                 : 
     289                 : void
     290               2 : TestULong(YAORB::CDR *cdr, FILE *output)
     291                 : {
     292                 :    CORBA::ULong ul ;
     293                 :    CORBA::ULong ulArray[3] ;
     294                 : 
     295                 :    // Expecting to read :
     296                 :    // 1 + 1 + 3 = 5 ULong
     297                 :    // 20 bytes total.
     298                 : 
     299               2 :    ul = 0 ;
     300               2 :    cdr->cdr_ULong(& ul) ;
     301               2 :    PrintULong(output, ul) ;
     302                 : 
     303               2 :    ul = 0 ;
     304               2 :    cdr->cdr_ULong(& ul) ;
     305               2 :    PrintULong(output, ul) ;
     306                 : 
     307               2 :    ulArray[0] = 0 ;
     308               2 :    ulArray[1] = 0 ;
     309               2 :    ulArray[2] = 0 ;
     310                 : 
     311               2 :    cdr->cdr_ULongArray(& ulArray[0], 3) ;
     312                 : 
     313               2 :    PrintULong(output, ulArray[0]) ;
     314               2 :    PrintULong(output, ulArray[1]) ;
     315               2 :    PrintULong(output, ulArray[2]) ;
     316                 : }
     317                 : 
     318                 : void
     319              10 : PrintLongLong(FILE *output, CORBA::LongLong ll)
     320                 : {
     321                 :    CORBA::ULong hi = 0 ;
     322                 :    CORBA::ULong lo = 0 ;
     323                 : 
     324              10 :    if (ll >= 0)
     325                 :    {
     326                 :       hi = ll >> 32 ;
     327                 :       lo = ll & 0xFFFFFFFF ;
     328               6 :       fprintf(output, "LongLong:0x%08x%08x\n", hi, lo) ;
     329                 :    }
     330                 :    else
     331                 :    {
     332                 :       hi = (-ll) >> 32 ;
     333                 :       lo = (-ll) & 0xFFFFFFFF ;
     334               4 :       fprintf(output, "LongLong:-0x%08x%08x\n", hi, lo) ;
     335                 :    }
     336                 : }
     337                 : 
     338                 : void
     339               2 : TestLongLong(YAORB::CDR *cdr, FILE *output)
     340                 : {
     341                 :    CORBA::LongLong ll ;
     342                 :    CORBA::LongLong llArray[3] ;
     343                 : 
     344                 :    // Expecting to read :
     345                 :    // 1 + 1 + 3 = 5 LongLong
     346                 :    // 40 bytes total.
     347                 : 
     348               2 :    ll = 0 ;
     349               2 :    cdr->cdr_LongLong(& ll) ;
     350               2 :    PrintLongLong(output, ll) ;
     351                 : 
     352               2 :    ll = 0 ;
     353               2 :    cdr->cdr_LongLong(& ll) ;
     354               2 :    PrintLongLong(output, ll) ;
     355                 : 
     356               2 :    llArray[0] = 0 ;
     357               2 :    llArray[1] = 0 ;
     358               2 :    llArray[2] = 0 ;
     359                 : 
     360               2 :    cdr->cdr_LongLongArray(& llArray[0], 3) ;
     361                 : 
     362               2 :    PrintLongLong(output, llArray[0]) ;
     363               2 :    PrintLongLong(output, llArray[1]) ;
     364               2 :    PrintLongLong(output, llArray[2]) ;
     365                 : }
     366                 : 
     367                 : void
     368              10 : PrintULongLong(FILE *output, CORBA::ULongLong ull)
     369                 : {
     370                 :    CORBA::ULong hi = 0 ;
     371                 :    CORBA::ULong lo = 0 ;
     372                 : 
     373                 :    hi = ull >> 32 ;
     374                 :    lo = ull & 0xFFFFFFFF ;
     375              10 :    fprintf(output, "ULongLong:0x%08x%08x\n", hi, lo) ;
     376                 : }
     377                 : 
     378                 : void
     379               2 : TestULongLong(YAORB::CDR *cdr, FILE *output)
     380                 : {
     381                 :    CORBA::ULongLong ull ;
     382                 :    CORBA::ULongLong ullArray[3] ;
     383                 : 
     384                 :    // Expecting to read :
     385                 :    // 1 + 1 + 3 = 5 ULongLong
     386                 :    // 40 bytes total.
     387                 : 
     388               2 :    ull = 0 ;
     389               2 :    cdr->cdr_ULongLong(& ull) ;
     390               2 :    PrintULongLong(output, ull) ;
     391                 : 
     392               2 :    ull = 0 ;
     393               2 :    cdr->cdr_ULongLong(& ull) ;
     394               2 :    PrintULongLong(output, ull) ;
     395                 : 
     396               2 :    ullArray[0] = 0 ;
     397               2 :    ullArray[1] = 0 ;
     398               2 :    ullArray[2] = 0 ;
     399                 : 
     400               2 :    cdr->cdr_ULongLongArray(& ullArray[0], 3) ;
     401                 : 
     402               2 :    PrintULongLong(output, ullArray[0]) ;
     403               2 :    PrintULongLong(output, ullArray[1]) ;
     404               2 :    PrintULongLong(output, ullArray[2]) ;
     405                 : }
     406                 : 
     407                 : void
     408               0 : TestFloat(YAORB::CDR *cdr, FILE *output)
     409                 : {
     410                 :    CORBA::Float f ;
     411                 :    CORBA::Float fArray[3] ;
     412                 : 
     413                 :    // FIXME : Expecting to write :
     414                 : 
     415               0 :    f = 0.0 ;
     416               0 :    cdr->cdr_Float(& f) ;
     417                 : 
     418               0 :    f = 0.0 ;
     419               0 :    cdr->cdr_Float(& f) ;
     420                 : 
     421               0 :    fArray[0] = 0.0 ;
     422               0 :    fArray[1] = 0.0 ;
     423               0 :    fArray[2] = 0.0 ;
     424                 : 
     425               0 :    cdr->cdr_FloatArray(& fArray[0], 3) ;
     426                 : }
     427                 : 
     428                 : void
     429               0 : TestDouble(YAORB::CDR *cdr, FILE *output)
     430                 : {
     431                 :    CORBA::Double d ;
     432                 :    CORBA::Double dArray[3] ;
     433                 : 
     434                 :    // FIXME : Expecting to write :
     435                 : 
     436               0 :    d = 0.0 ;
     437               0 :    cdr->cdr_Double(& d) ;
     438                 : 
     439               0 :    d = 0.0 ;
     440               0 :    cdr->cdr_Double(& d) ;
     441                 : 
     442               0 :    dArray[0] = 0.0 ;
     443               0 :    dArray[1] = 0.0 ;
     444               0 :    dArray[2] = 0.0 ;
     445                 : 
     446               0 :    cdr->cdr_DoubleArray(& dArray[0], 3) ;
     447                 : }
     448                 : 
     449                 : void
     450               0 : TestLongDouble(YAORB::CDR *cdr, FILE *output)
     451                 : {
     452                 :    CORBA::LongDouble ld ;
     453                 :    CORBA::LongDouble ldArray[3] ;
     454                 : 
     455                 :    // FIXME : Expecting to write :
     456                 : 
     457               0 :    ld = 0.0 ;
     458               0 :    cdr->cdr_LongDouble(& ld) ;
     459                 : 
     460               0 :    ld = 0.0 ;
     461               0 :    cdr->cdr_LongDouble(& ld) ;
     462                 : 
     463               0 :    ldArray[0] = 0.0 ;
     464               0 :    ldArray[1] = 0.0 ;
     465               0 :    ldArray[2] = 0.0 ;
     466                 : 
     467               0 :    cdr->cdr_LongDoubleArray(& ldArray[0], 3) ;
     468                 : }
     469                 : 
     470              18 : int main(int argc, char* argv[])
     471                 : {
     472              18 :    if (argc < 3)
     473                 :    {
     474               0 :       fprintf(stderr, "TestCdrRead failed : bad arguments\n") ;
     475               0 :       return (-1) ;
     476                 :    }
     477                 : 
     478              18 :    const char* inputFileName = argv[1] ;
     479                 :    const char* outputFileName = argv[2] ;
     480                 : 
     481              18 :    FILE *output = fopen(outputFileName, "w") ;
     482                 : 
     483              18 :    if (output == NULL)
     484                 :    {
     485               0 :       fprintf(stderr, "TestCdrRead failed : bad output\n") ;
     486               0 :       return (-2) ;
     487                 :    }
     488                 : 
     489                 :    try
     490                 :    {
     491              18 :       CDRFile cdr(inputFileName, YAORB::CDR_READ) ;
     492                 : 
     493              18 :       cdr.cdr_ByteOrder() ;
     494                 : 
     495              18 :       CORBA::Octet test = 0 ;
     496              18 :       cdr.cdr_Octet(& test) ;
     497                 : 
     498              18 :       fprintf(output, "Performing test %d.\n", test) ;
     499                 : 
     500                 :       CORBA::Char comments[15] ;
     501              18 :       cdr.cdr_CharArray(& comments[0], 14) ;
     502              18 :       comments[14] = '\0' ;
     503                 : 
     504              18 :       fprintf(output, "test comments : <%s>\n", comments) ;
     505                 : 
     506                 :       // We start the test on a 16 bytes boundary :
     507                 :       // 1 byte : byte order
     508                 :       // 1 byte : test number
     509                 :       // 14 bytes : comments
     510                 : 
     511              18 :       switch(test)
     512                 :       {
     513                 :          case 1:
     514                 :          {
     515               2 :             TestBool(& cdr, output) ;
     516                 :             break ;
     517                 :          }
     518                 :          case 2:
     519                 :          {
     520               2 :             TestOctet(& cdr, output) ;
     521                 :             break ;
     522                 :          }
     523                 :          case 3:
     524                 :          {
     525               2 :             TestChar(& cdr, output) ;
     526                 :             break ;
     527                 :          }
     528                 :          case 4:
     529                 :          {
     530                 :             TestWChar(& cdr, output) ;
     531                 :             break ;
     532                 :          }
     533                 :          case 5:
     534                 :          {
     535               2 :             TestShort(& cdr, output) ;
     536                 :             break ;
     537                 :          }
     538                 :          case 6:
     539                 :          {
     540               2 :             TestUShort(& cdr, output) ;
     541                 :             break ;
     542                 :          }
     543                 :          case 7:
     544                 :          {
     545               2 :             TestLong(& cdr, output) ;
     546                 :             break ;
     547                 :          }
     548                 :          case 8:
     549                 :          {
     550               2 :             TestULong(& cdr, output) ;
     551                 :             break ;
     552                 :          }
     553                 :          case 9:
     554                 :          {
     555               2 :             TestLongLong(& cdr, output) ;
     556                 :             break ;
     557                 :          }
     558                 :          case 10:
     559                 :          {
     560               2 :             TestULongLong(& cdr, output) ;
     561                 :             break ;
     562                 :          }
     563                 :          case 11:
     564                 :          {
     565               0 :             TestFloat(& cdr, output) ;
     566                 :             break ;
     567                 :          }
     568                 :          case 12:
     569                 :          {
     570               0 :             TestDouble(& cdr, output) ;
     571                 :             break ;
     572                 :          }
     573                 :          case 13:
     574                 :          {
     575               0 :             TestLongDouble(& cdr, output) ;
     576                 :             break ;
     577                 :          }
     578                 :          default :
     579                 :          {
     580                 :             fprintf(
     581                 :                output,
     582                 :                "TestCdrRead failed : Unexpected test number %d.\n",
     583               0 :                test) ;
     584                 :             break ;
     585                 :          }
     586               0 :       }
     587                 :    }
     588              18 :    catch (...)
     589                 :    {
     590               0 :       fprintf(stderr, "TestCdrRead failed : exception\n") ;
     591               0 :       return (-4) ;
     592                 :    }
     593                 : 
     594              18 :    fclose (output) ;
     595                 :    return 0;
     596                 : }
     597                 : 

Generated by: LTP GCOV extension version 1.4