Coverage report for dbus/dbus-marshal-validate-util.c.gcov

        -:    0:Source:dbus-marshal-validate-util.c
        -:    0:Graph:.libs/dbus-marshal-validate-util.gcno
        -:    0:Data:.libs/dbus-marshal-validate-util.gcda
        -:    0:Runs:767
        -:    0:Programs:1
        -:    1:/* -*- mode: C; c-file-style: "gnu" -*- */
        -:    2:/* dbus-marshal-validate-util.c Would be in dbus-marshal-validate.c, but only used by tests/bus
        -:    3: *
        -:    4: * Copyright (C) 2005 Red Hat, Inc.
        -:    5: *
        -:    6: * Licensed under the Academic Free License version 2.1
        -:    7: *
        -:    8: * This program is free software; you can redistribute it and/or modify
        -:    9: * it under the terms of the GNU General Public License as published by
        -:   10: * the Free Software Foundation; either version 2 of the License, or
        -:   11: * (at your option) any later version.
        -:   12: *
        -:   13: * This program is distributed in the hope that it will be useful,
        -:   14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   16: * GNU General Public License for more details.
        -:   17: *
        -:   18: * You should have received a copy of the GNU General Public License
        -:   19: * along with this program; if not, write to the Free Software
        -:   20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        -:   21: *
        -:   22: */
        -:   23:
        -:   24:#include <config.h>
        -:   25:#ifdef DBUS_BUILD_TESTS
        -:   26:#include "dbus-internals.h"
        -:   27:#include "dbus-marshal-validate.h"
        -:   28:#include "dbus-marshal-recursive.h"
        -:   29:
        -:   30:#include "dbus-test.h"
        -:   31:#include <stdio.h>
        -:   32:
        -:   33:typedef struct
        -:   34:{
        -:   35:  const char *data;
        -:   36:  DBusValidity expected;
        -:   37:} ValidityTest;
        -:   38:
        -:   39:static void
        -:   40:run_validity_tests (const ValidityTest *tests,
        -:   41:                    int                 n_tests,
        -:   42:                    DBusValidity (* func) (const DBusString*,int,int))
function run_validity_tests called 1 returned 100% blocks executed 80%
        1:   43:{
        -:   44:  int i;
        -:   45:
       15:   46:  for (i = 0; i < n_tests; i++)
branch  0 taken 93%
branch  1 taken 7% (fallthrough)
        -:   47:    {
        -:   48:      DBusString str;
        -:   49:      DBusValidity v;
        -:   50:
       14:   51:      _dbus_string_init_const (&str, tests[i].data);
call    0 returned 100%
        -:   52:
       14:   53:      v = (*func) (&str, 0, _dbus_string_get_length (&str));
call    0 returned 100%
call    1 returned 100%
        -:   54:
       14:   55:      if (v != tests[i].expected)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:   56:        {
    #####:   57:          _dbus_warn ("Improper validation result %d for '%s'\n",
call    0 never executed
        -:   58:                      v, tests[i].data);
    #####:   59:          _dbus_assert_not_reached ("test failed");
call    0 never executed
        -:   60:        }
        -:   61:
       14:   62:      ++i;
        -:   63:    }
        1:   64:}
        -:   65:
        -:   66:static const ValidityTest signature_tests[] = {
        -:   67:  { "", DBUS_VALID },
        -:   68:  { "i", DBUS_VALID },
        -:   69:  { "ai", DBUS_VALID },
        -:   70:  { "(i)", DBUS_VALID },
        -:   71:  { "w", DBUS_INVALID_UNKNOWN_TYPECODE },
        -:   72:  { "a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
        -:   73:  { "aaaaaa", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
        -:   74:  { "ii(ii)a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
        -:   75:  { "ia", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
        -:   76:  /* DBUS_INVALID_SIGNATURE_TOO_LONG, */ /* too hard to test this way */
        -:   77:  { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
        -:   78:    DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION },
        -:   79:  { "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((ii))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))",
        -:   80:    DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION },
        -:   81:  { ")", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
        -:   82:  { "i)", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
        -:   83:  { "a)", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
        -:   84:  { "(", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
        -:   85:  { "(i", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
        -:   86:  { "(iiiii", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
        -:   87:  { "(ai", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
        -:   88:  { "()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
        -:   89:  { "(())", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
        -:   90:  { "a()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
        -:   91:  { "i()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
        -:   92:  { "()i", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
        -:   93:  { "(a)", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
        -:   94:  { "a{ia}", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
        -:   95:  { "a{}", DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS },
        -:   96:  { "a{aii}", DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE },
        -:   97:  /* { "a{i}", DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD }, */
        -:   98:  /* { "{is}", DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY }, */
        -:   99:  /* { "a{isi}", DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS }, */
        -:  100:};
        -:  101:
        -:  102:dbus_bool_t
        -:  103:_dbus_marshal_validate_test (void)
function _dbus_marshal_validate_test called 1 returned 100% blocks executed 76%
        1:  104:{
        -:  105:  DBusString str;
        -:  106:  int i;
        -:  107:
        -:  108:  const char *valid_paths[] = {
        -:  109:    "/",
        -:  110:    "/foo/bar",
        -:  111:    "/foo",
        -:  112:    "/foo/bar/baz"
        1:  113:  };
        -:  114:  const char *invalid_paths[] = {
        -:  115:    "bar",
        -:  116:    "bar/baz",
        -:  117:    "/foo/bar/",
        -:  118:    "/foo/"
        -:  119:    "foo/",
        -:  120:    "boo//blah",
        -:  121:    "//",
        -:  122:    "///",
        -:  123:    "foo///blah/",
        -:  124:    "Hello World",
        -:  125:    "",
        -:  126:    "   ",
        -:  127:    "foo bar"
        1:  128:  };
        -:  129:
        -:  130:  const char *valid_interfaces[] = {
        -:  131:    "org.freedesktop.Foo",
        -:  132:    "Bar.Baz",
        -:  133:    "Blah.Blah.Blah.Blah.Blah",
        -:  134:    "a.b",
        -:  135:    "a.b.c.d.e.f.g",
        -:  136:    "a0.b1.c2.d3.e4.f5.g6",
        -:  137:    "abc123.foo27"
        1:  138:  };
        -:  139:  const char *invalid_interfaces[] = {
        -:  140:    ".",
        -:  141:    "",
        -:  142:    "..",
        -:  143:    ".Foo.Bar",
        -:  144:    "..Foo.Bar",
        -:  145:    "Foo.Bar.",
        -:  146:    "Foo.Bar..",
        -:  147:    "Foo",
        -:  148:    "9foo.bar.baz",
        -:  149:    "foo.bar..baz",
        -:  150:    "foo.bar...baz",
        -:  151:    "foo.bar.b..blah",
        -:  152:    ":",
        -:  153:    ":0-1",
        -:  154:    "10",
        -:  155:    ":11.34324",
        -:  156:    "0.0.0",
        -:  157:    "0..0",
        -:  158:    "foo.Bar.%",
        -:  159:    "foo.Bar!!",
        -:  160:    "!Foo.bar.bz",
        -:  161:    "foo.$.blah",
        -:  162:    "",
        -:  163:    "   ",
        -:  164:    "foo bar"
        1:  165:  };
        -:  166:
        -:  167:  const char *valid_unique_names[] = {
        -:  168:    ":0",
        -:  169:    ":a",
        -:  170:    ":",
        -:  171:    ":.a",
        -:  172:    ":.1",
        -:  173:    ":0.1",
        -:  174:    ":000.2222",
        -:  175:    ":.blah",
        -:  176:    ":abce.freedesktop.blah"
        1:  177:  };
        -:  178:  const char *invalid_unique_names[] = {
        -:  179:    //":-",
        -:  180:    ":!",
        -:  181:    //":0-10",
        -:  182:    ":blah.",
        -:  183:    ":blah.",
        -:  184:    ":blah..org",
        -:  185:    ":blah.org..",
        -:  186:    ":..blah.org",
        -:  187:    "",
        -:  188:    "   ",
        -:  189:    "foo bar"
        1:  190:  };
        -:  191:
        -:  192:  const char *valid_members[] = {
        -:  193:    "Hello",
        -:  194:    "Bar",
        -:  195:    "foobar",
        -:  196:    "_foobar",
        -:  197:    "foo89"
        1:  198:  };
        -:  199:
        -:  200:  const char *invalid_members[] = {
        -:  201:    "9Hello",
        -:  202:    "10",
        -:  203:    "1",
        -:  204:    "foo-bar",
        -:  205:    "blah.org",
        -:  206:    ".blah",
        -:  207:    "blah.",
        -:  208:    "Hello.",
        -:  209:    "!foo",
        -:  210:    "",
        -:  211:    "   ",
        -:  212:    "foo bar"
        1:  213:  };
        -:  214:
        -:  215:  const char *valid_signatures[] = {
        -:  216:    "",
        -:  217:    "sss",
        -:  218:    "i",
        -:  219:    "b"
        1:  220:  };
        -:  221:
        -:  222:  const char *invalid_signatures[] = {
        -:  223:    " ",
        -:  224:    "not a valid signature",
        -:  225:    "123",
        -:  226:    ".",
        -:  227:    "("
        1:  228:  };
        -:  229:
        -:  230:  /* Signature with reason */
        -:  231:
        1:  232:  run_validity_tests (signature_tests, _DBUS_N_ELEMENTS (signature_tests),
call    0 returned 100%
        -:  233:                      _dbus_validate_signature_with_reason);
        -:  234:
        -:  235:  /* Path validation */
        1:  236:  i = 0;
        6:  237:  while (i < (int) _DBUS_N_ELEMENTS (valid_paths))
branch  0 taken 80%
branch  1 taken 20% (fallthrough)
        -:  238:    {
        4:  239:      _dbus_string_init_const (&str, valid_paths[i]);
call    0 returned 100%
        -:  240:
        4:  241:      if (!_dbus_validate_path (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  242:                                _dbus_string_get_length (&str)))
        -:  243:        {
    #####:  244:          _dbus_warn ("Path \"%s\" should have been valid\n", valid_paths[i]);
call    0 never executed
    #####:  245:          _dbus_assert_not_reached ("invalid path");
call    0 never executed
        -:  246:        }
        -:  247:
        4:  248:      ++i;
        -:  249:    }
        -:  250:
        1:  251:  i = 0;
       14:  252:  while (i < (int) _DBUS_N_ELEMENTS (invalid_paths))
branch  0 taken 92%
branch  1 taken 8% (fallthrough)
        -:  253:    {
       12:  254:      _dbus_string_init_const (&str, invalid_paths[i]);
call    0 returned 100%
        -:  255:
       12:  256:      if (_dbus_validate_path (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  257:                               _dbus_string_get_length (&str)))
        -:  258:        {
    #####:  259:          _dbus_warn ("Path \"%s\" should have been invalid\n", invalid_paths[i]);
call    0 never executed
    #####:  260:          _dbus_assert_not_reached ("valid path");
call    0 never executed
        -:  261:        }
        -:  262:
       12:  263:      ++i;
        -:  264:    }
        -:  265:
        -:  266:  /* Interface validation */
        1:  267:  i = 0;
        9:  268:  while (i < (int) _DBUS_N_ELEMENTS (valid_interfaces))
branch  0 taken 88%
branch  1 taken 13% (fallthrough)
        -:  269:    {
        7:  270:      _dbus_string_init_const (&str, valid_interfaces[i]);
call    0 returned 100%
        -:  271:
        7:  272:      if (!_dbus_validate_interface (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  273:                                     _dbus_string_get_length (&str)))
        -:  274:        {
    #####:  275:          _dbus_warn ("Interface \"%s\" should have been valid\n", valid_interfaces[i]);
call    0 never executed
    #####:  276:          _dbus_assert_not_reached ("invalid interface");
call    0 never executed
        -:  277:        }
        -:  278:
        7:  279:      ++i;
        -:  280:    }
        -:  281:
        1:  282:  i = 0;
       27:  283:  while (i < (int) _DBUS_N_ELEMENTS (invalid_interfaces))
branch  0 taken 96%
branch  1 taken 4% (fallthrough)
        -:  284:    {
       25:  285:      _dbus_string_init_const (&str, invalid_interfaces[i]);
call    0 returned 100%
        -:  286:
       25:  287:      if (_dbus_validate_interface (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  288:                                    _dbus_string_get_length (&str)))
        -:  289:        {
    #####:  290:          _dbus_warn ("Interface \"%s\" should have been invalid\n", invalid_interfaces[i]);
call    0 never executed
    #####:  291:          _dbus_assert_not_reached ("valid interface");
call    0 never executed
        -:  292:        }
        -:  293:
       25:  294:      ++i;
        -:  295:    }
        -:  296:
        -:  297:  /* Bus name validation (check that valid interfaces are valid bus names,
        -:  298:   * and invalid interfaces are invalid services except if they start with ':')
        -:  299:   */
        1:  300:  i = 0;
        9:  301:  while (i < (int) _DBUS_N_ELEMENTS (valid_interfaces))
branch  0 taken 88%
branch  1 taken 13% (fallthrough)
        -:  302:    {
        7:  303:      _dbus_string_init_const (&str, valid_interfaces[i]);
call    0 returned 100%
        -:  304:
        7:  305:      if (!_dbus_validate_bus_name (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  306:                                   _dbus_string_get_length (&str)))
        -:  307:        {
    #####:  308:          _dbus_warn ("Bus name \"%s\" should have been valid\n", valid_interfaces[i]);
call    0 never executed
    #####:  309:          _dbus_assert_not_reached ("invalid bus name");
call    0 never executed
        -:  310:        }
        -:  311:
        7:  312:      ++i;
        -:  313:    }
        -:  314:
        1:  315:  i = 0;
       27:  316:  while (i < (int) _DBUS_N_ELEMENTS (invalid_interfaces))
branch  0 taken 96%
branch  1 taken 4% (fallthrough)
        -:  317:    {
       25:  318:      if (invalid_interfaces[i][0] != ':')
branch  0 taken 88% (fallthrough)
branch  1 taken 12%
        -:  319:        {
       22:  320:          _dbus_string_init_const (&str, invalid_interfaces[i]);
call    0 returned 100%
        -:  321:
       22:  322:          if (_dbus_validate_bus_name (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  323:                                       _dbus_string_get_length (&str)))
        -:  324:            {
    #####:  325:              _dbus_warn ("Bus name \"%s\" should have been invalid\n", invalid_interfaces[i]);
call    0 never executed
    #####:  326:              _dbus_assert_not_reached ("valid bus name");
call    0 never executed
        -:  327:            }
        -:  328:        }
        -:  329:
       25:  330:      ++i;
        -:  331:    }
        -:  332:
        -:  333:  /* unique name validation */
        1:  334:  i = 0;
       11:  335:  while (i < (int) _DBUS_N_ELEMENTS (valid_unique_names))
branch  0 taken 90%
branch  1 taken 10% (fallthrough)
        -:  336:    {
        9:  337:      _dbus_string_init_const (&str, valid_unique_names[i]);
call    0 returned 100%
        -:  338:
        9:  339:      if (!_dbus_validate_bus_name (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  340:                                    _dbus_string_get_length (&str)))
        -:  341:        {
    #####:  342:          _dbus_warn ("Bus name \"%s\" should have been valid\n", valid_unique_names[i]);
call    0 never executed
    #####:  343:          _dbus_assert_not_reached ("invalid unique name");
call    0 never executed
        -:  344:        }
        -:  345:
        9:  346:      ++i;
        -:  347:    }
        -:  348:
        1:  349:  i = 0;
       11:  350:  while (i < (int) _DBUS_N_ELEMENTS (invalid_unique_names))
branch  0 taken 90%
branch  1 taken 10% (fallthrough)
        -:  351:    {
        9:  352:      _dbus_string_init_const (&str, invalid_unique_names[i]);
call    0 returned 100%
        -:  353:
        9:  354:      if (_dbus_validate_bus_name (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  355:                                   _dbus_string_get_length (&str)))
        -:  356:        {
    #####:  357:          _dbus_warn ("Bus name \"%s\" should have been invalid\n", invalid_unique_names[i]);
call    0 never executed
    #####:  358:          _dbus_assert_not_reached ("valid unique name");
call    0 never executed
        -:  359:        }
        -:  360:
        9:  361:      ++i;
        -:  362:    }
        -:  363:
        -:  364:
        -:  365:  /* Error name validation (currently identical to interfaces)
        -:  366:   */
        1:  367:  i = 0;
        9:  368:  while (i < (int) _DBUS_N_ELEMENTS (valid_interfaces))
branch  0 taken 88%
branch  1 taken 13% (fallthrough)
        -:  369:    {
        7:  370:      _dbus_string_init_const (&str, valid_interfaces[i]);
call    0 returned 100%
        -:  371:
        7:  372:      if (!_dbus_validate_error_name (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  373:                                      _dbus_string_get_length (&str)))
        -:  374:        {
    #####:  375:          _dbus_warn ("Error name \"%s\" should have been valid\n", valid_interfaces[i]);
call    0 never executed
    #####:  376:          _dbus_assert_not_reached ("invalid error name");
call    0 never executed
        -:  377:        }
        -:  378:
        7:  379:      ++i;
        -:  380:    }
        -:  381:
        1:  382:  i = 0;
       27:  383:  while (i < (int) _DBUS_N_ELEMENTS (invalid_interfaces))
branch  0 taken 96%
branch  1 taken 4% (fallthrough)
        -:  384:    {
       25:  385:      if (invalid_interfaces[i][0] != ':')
branch  0 taken 88% (fallthrough)
branch  1 taken 12%
        -:  386:        {
       22:  387:          _dbus_string_init_const (&str, invalid_interfaces[i]);
call    0 returned 100%
        -:  388:
       22:  389:          if (_dbus_validate_error_name (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  390:                                         _dbus_string_get_length (&str)))
        -:  391:            {
    #####:  392:              _dbus_warn ("Error name \"%s\" should have been invalid\n", invalid_interfaces[i]);
call    0 never executed
    #####:  393:              _dbus_assert_not_reached ("valid error name");
call    0 never executed
        -:  394:            }
        -:  395:        }
        -:  396:
       25:  397:      ++i;
        -:  398:    }
        -:  399:
        -:  400:  /* Member validation */
        1:  401:  i = 0;
        7:  402:  while (i < (int) _DBUS_N_ELEMENTS (valid_members))
branch  0 taken 83%
branch  1 taken 17% (fallthrough)
        -:  403:    {
        5:  404:      _dbus_string_init_const (&str, valid_members[i]);
call    0 returned 100%
        -:  405:
        5:  406:      if (!_dbus_validate_member (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  407:                                  _dbus_string_get_length (&str)))
        -:  408:        {
    #####:  409:          _dbus_warn ("Member \"%s\" should have been valid\n", valid_members[i]);
call    0 never executed
    #####:  410:          _dbus_assert_not_reached ("invalid member");
call    0 never executed
        -:  411:        }
        -:  412:
        5:  413:      ++i;
        -:  414:    }
        -:  415:
        1:  416:  i = 0;
       14:  417:  while (i < (int) _DBUS_N_ELEMENTS (invalid_members))
branch  0 taken 92%
branch  1 taken 8% (fallthrough)
        -:  418:    {
       12:  419:      _dbus_string_init_const (&str, invalid_members[i]);
call    0 returned 100%
        -:  420:
       12:  421:      if (_dbus_validate_member (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  422:                                 _dbus_string_get_length (&str)))
        -:  423:        {
    #####:  424:          _dbus_warn ("Member \"%s\" should have been invalid\n", invalid_members[i]);
call    0 never executed
    #####:  425:          _dbus_assert_not_reached ("valid member");
call    0 never executed
        -:  426:        }
        -:  427:
       12:  428:      ++i;
        -:  429:    }
        -:  430:
        -:  431:  /* Signature validation */
        1:  432:  i = 0;
        6:  433:  while (i < (int) _DBUS_N_ELEMENTS (valid_signatures))
branch  0 taken 80%
branch  1 taken 20% (fallthrough)
        -:  434:    {
        4:  435:      _dbus_string_init_const (&str, valid_signatures[i]);
call    0 returned 100%
        -:  436:
        4:  437:      if (!_dbus_validate_signature (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  438:                                     _dbus_string_get_length (&str)))
        -:  439:        {
    #####:  440:          _dbus_warn ("Signature \"%s\" should have been valid\n", valid_signatures[i]);
call    0 never executed
    #####:  441:          _dbus_assert_not_reached ("invalid signature");
call    0 never executed
        -:  442:        }
        -:  443:
        4:  444:      ++i;
        -:  445:    }
        -:  446:
        1:  447:  i = 0;
        7:  448:  while (i < (int) _DBUS_N_ELEMENTS (invalid_signatures))
branch  0 taken 83%
branch  1 taken 17% (fallthrough)
        -:  449:    {
        5:  450:      _dbus_string_init_const (&str, invalid_signatures[i]);
call    0 returned 100%
        -:  451:
        5:  452:      if (_dbus_validate_signature (&str, 0,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  453:                                    _dbus_string_get_length (&str)))
        -:  454:        {
    #####:  455:          _dbus_warn ("Signature \"%s\" should have been invalid\n", invalid_signatures[i]);
call    0 never executed
    #####:  456:          _dbus_assert_not_reached ("valid signature");
call    0 never executed
        -:  457:        }
        -:  458:
        5:  459:      ++i;
        -:  460:    }
        -:  461:
        -:  462:  /* Validate claimed length longer than real length */
        1:  463:  _dbus_string_init_const (&str, "abc.efg");
call    0 returned 100%
        1:  464:  if (_dbus_validate_bus_name (&str, 0, 8))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  465:    _dbus_assert_not_reached ("validated too-long string");
call    0 never executed
        1:  466:  if (_dbus_validate_interface (&str, 0, 8))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  467:    _dbus_assert_not_reached ("validated too-long string");
call    0 never executed
        1:  468:  if (_dbus_validate_error_name (&str, 0, 8))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  469:    _dbus_assert_not_reached ("validated too-long string");
call    0 never executed
        -:  470:
        1:  471:  _dbus_string_init_const (&str, "abc");
call    0 returned 100%
        1:  472:  if (_dbus_validate_member (&str, 0, 4))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  473:    _dbus_assert_not_reached ("validated too-long string");
call    0 never executed
        -:  474:
        1:  475:  _dbus_string_init_const (&str, "sss");
call    0 returned 100%
        1:  476:  if (_dbus_validate_signature (&str, 0, 4))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  477:    _dbus_assert_not_reached ("validated too-long signature");
call    0 never executed
        -:  478:
        -:  479:  /* Validate string exceeding max name length */
        1:  480:  if (!_dbus_string_init (&str))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  481:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  482:
       39:  483:  while (_dbus_string_get_length (&str) <= DBUS_MAXIMUM_NAME_LENGTH)
call    0 returned 100%
branch  1 taken 97%
branch  2 taken 3% (fallthrough)
       37:  484:    if (!_dbus_string_append (&str, "abc.def"))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  485:      _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  486:
        1:  487:  if (_dbus_validate_bus_name (&str, 0, _dbus_string_get_length (&str)))
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
    #####:  488:    _dbus_assert_not_reached ("validated overmax string");
call    0 never executed
        1:  489:  if (_dbus_validate_interface (&str, 0, _dbus_string_get_length (&str)))
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
    #####:  490:    _dbus_assert_not_reached ("validated overmax string");
call    0 never executed
        1:  491:  if (_dbus_validate_error_name (&str, 0, _dbus_string_get_length (&str)))
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
    #####:  492:    _dbus_assert_not_reached ("validated overmax string");
call    0 never executed
        -:  493:
        -:  494:  /* overlong member */
        1:  495:  _dbus_string_set_length (&str, 0);
call    0 returned 100%
        1:  496:  while (_dbus_string_get_length (&str) <= DBUS_MAXIMUM_NAME_LENGTH)
call    0 returned 100%
branch  1 taken 99%
branch  2 taken 1% (fallthrough)
       86:  497:    if (!_dbus_string_append (&str, "abc"))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  498:      _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  499:
        1:  500:  if (_dbus_validate_member (&str, 0, _dbus_string_get_length (&str)))
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
    #####:  501:    _dbus_assert_not_reached ("validated overmax string");
call    0 never executed
        -:  502:
        -:  503:  /* overlong unique name */
        1:  504:  _dbus_string_set_length (&str, 0);
call    0 returned 100%
        1:  505:  _dbus_string_append (&str, ":");
call    0 returned 100%
        1:  506:  while (_dbus_string_get_length (&str) <= DBUS_MAXIMUM_NAME_LENGTH)
call    0 returned 100%
branch  1 taken 99%
branch  2 taken 1% (fallthrough)
       85:  507:    if (!_dbus_string_append (&str, "abc"))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  508:      _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  509:
        1:  510:  if (_dbus_validate_bus_name (&str, 0, _dbus_string_get_length (&str)))
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
    #####:  511:    _dbus_assert_not_reached ("validated overmax string");
call    0 never executed
        -:  512:
        1:  513:  _dbus_string_free (&str);
call    0 returned 100%
        -:  514:
        -:  515:  /* Body validation; test basic validation of valid bodies for both endian */
        -:  516:  
        -:  517:  {
        -:  518:    int sequence;
        -:  519:    DBusString signature;
        -:  520:    DBusString body;
        -:  521:
        1:  522:    if (!_dbus_string_init (&signature) || !_dbus_string_init (&body))
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
call    3 returned 100%
branch  4 taken 0% (fallthrough)
branch  5 taken 100%
    #####:  523:      _dbus_assert_not_reached ("oom");
call    0 never executed
        -:  524:
        1:  525:    sequence = 0;
      122:  526:    while (dbus_internal_do_not_use_generate_bodies (sequence,
call    0 returned 100%
branch  1 taken 99%
branch  2 taken 1% (fallthrough)
        -:  527:                                                     DBUS_LITTLE_ENDIAN,
        -:  528:                                                     &signature, &body))
        -:  529:      {
        -:  530:        DBusValidity validity;
        -:  531:
      120:  532:        validity = _dbus_validate_body_with_reason (&signature, 0,
call    0 returned 100%
call    1 returned 100%
        -:  533:                                                    DBUS_LITTLE_ENDIAN,
        -:  534:                                                    NULL, &body, 0,
        -:  535:                                                    _dbus_string_get_length (&body));
      120:  536:        if (validity != DBUS_VALID)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  537:          {
    #####:  538:            _dbus_warn ("invalid code %d expected valid on sequence %d little endian\n",
call    0 never executed
        -:  539:                        validity, sequence);
    #####:  540:            _dbus_verbose_bytes_of_string (&signature, 0, _dbus_string_get_length (&signature));
call    0 never executed
call    1 never executed
    #####:  541:            _dbus_verbose_bytes_of_string (&body, 0, _dbus_string_get_length (&body));
call    0 never executed
call    1 never executed
    #####:  542:            _dbus_assert_not_reached ("test failed");
call    0 never executed
        -:  543:          }
        -:  544:
      120:  545:        _dbus_string_set_length (&signature, 0);
call    0 returned 100%
      120:  546:        _dbus_string_set_length (&body, 0);
call    0 returned 100%
      120:  547:        ++sequence;
        -:  548:      }
        -:  549:                                                     
        1:  550:    sequence = 0;
      122:  551:    while (dbus_internal_do_not_use_generate_bodies (sequence,
call    0 returned 100%
branch  1 taken 99%
branch  2 taken 1% (fallthrough)
        -:  552:                                                     DBUS_BIG_ENDIAN,
        -:  553:                                                     &signature, &body))
        -:  554:      {
        -:  555:        DBusValidity validity;
        -:  556:
      120:  557:        validity = _dbus_validate_body_with_reason (&signature, 0,
call    0 returned 100%
call    1 returned 100%
        -:  558:                                                    DBUS_BIG_ENDIAN,
        -:  559:                                                    NULL, &body, 0,
        -:  560:                                                    _dbus_string_get_length (&body));
      120:  561:        if (validity != DBUS_VALID)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  562:          {
    #####:  563:            _dbus_warn ("invalid code %d expected valid on sequence %d big endian\n",
call    0 never executed
        -:  564:                        validity, sequence);
    #####:  565:            _dbus_verbose_bytes_of_string (&signature, 0, _dbus_string_get_length (&signature));
call    0 never executed
call    1 never executed
    #####:  566:            _dbus_verbose_bytes_of_string (&body, 0, _dbus_string_get_length (&body));
call    0 never executed
call    1 never executed
    #####:  567:            _dbus_assert_not_reached ("test failed");
call    0 never executed
        -:  568:          }
        -:  569:
      120:  570:        _dbus_string_set_length (&signature, 0);
call    0 returned 100%
      120:  571:        _dbus_string_set_length (&body, 0);
call    0 returned 100%
      120:  572:        ++sequence;
        -:  573:      }
        -:  574:
        1:  575:    _dbus_string_free (&signature);
call    0 returned 100%
        1:  576:    _dbus_string_free (&body);
call    0 returned 100%
        -:  577:  }
        -:  578:  
        1:  579:  return TRUE;
        -:  580:}
        -:  581:
        -:  582:#endif /* DBUS_BUILD_TESTS */