IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 31, 2019, 12:03:15 PM (7 years ago)
Author:
eugene
Message:

add tests to count instances

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20191011/Nebulous/nebclient/tests/tests.c

    r24999 r41021  
    1616    if (foo) nebFree(foo)
    1717
     18int show_instances (nebServer *server, char *key) {
     19
     20  nebObjectInstances *locations = NULL;
     21
     22  locations = nebFindInstances(server, key, NULL);
     23
     24  for (int i = 0; i < locations->n; i++) {
     25    fprintf (stderr, "# loc %d : %s\n", i, locations->URI[i]);
     26  }
     27  nebObjectInstancesFree(locations);
     28  return 1;
     29}
     30
     31int count_instances (nebServer *server, char *key) {
     32
     33  nebObjectInstances *locations = NULL;
     34  locations = nebFindInstances(server, key, NULL);
     35  int Ninstances = locations ? locations->n : 0;
     36  nebObjectInstancesFree(locations);
     37  return Ninstances;
     38}
     39
    1840int main (int argc, char **argv) {
    1941    nebServer       *server = NULL;
    2042    char            *key = "foobarbaz";
    2143
    22     plan_tests(31);
     44    plan_tests(37);
    2345
    2446    if (getenv("NEB_SERVER")) {
     
    3759        filename = nebCreate(server, key, NULL, &URI);
    3860        diag("filename is %s", filename);
     61
     62        show_instances (server, key);
     63        ok (count_instances (server, key) == 1, "correct instance count");
     64
    3965        neb_ok(server, filename, "create object");
    4066        ok(URI, "URI not NULL");
     
    5379        neb_ok(server, fh > -1, "create new object filehandle");
    5480        ok(URI, "URI not NULL");
     81        ok (count_instances (server, key) == 1, "correct instance count");
    5582
    5683        tst_nebFree(URI);
    5784        close(fh);
    5885    }
     86
     87    show_instances (server, key);
    5988
    6089    {
     
    80109    }
    81110
    82 
    83111    neb_ok(server, nebReplicate(server, key, NULL, NULL), "replicate object");
     112    show_instances (server, key);
     113    ok (count_instances (server, key) == 2, "correct instance count");
    84114
    85115    neb_ok(server, nebOpen(server, key, NEB_WRITE) < 0, "write to object with multiple instances");
     116    show_instances (server, key);
    86117
    87118    neb_ok(server, nebCull(server, key), "cull object");
     119    show_instances (server, key);
     120    ok (count_instances (server, key) == 1, "correct instance count");
     121
     122    neb_ok(server, nebCull(server, key) == 0, "cannot cull object with one instance");
     123    show_instances (server, key);
     124    ok (count_instances (server, key) == 1, "correct instance count");
    88125
    89126    neb_ok(server, nebStat(server, key), "stat object");
     127    show_instances (server, key);
    90128
    91129    neb_ok(server, nebLock(server, key, NEB_WRITE), "lock object write");
Note: See TracChangeset for help on using the changeset viewer.