Remove Nanomsg library generation
[ric-plt/lib/rmr.git] / test / rt_static_test.c
index f1e6981..13a216b 100644 (file)
@@ -1,14 +1,14 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-        Copyright (c) 2019 Nokia 
-        Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019 Nokia
+           Copyright (c) 2018-2019 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
-       http://www.apache.org/licenses/LICENSE-2.0
+          http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,7 +21,7 @@
 /*
        Mmemonic:       rt_static_test.c
        Abstract:       Test the route table funcitons. These are meant to be included at compile
 /*
        Mmemonic:       rt_static_test.c
        Abstract:       Test the route table funcitons. These are meant to be included at compile
-                               time by the test driver.  
+                               time by the test driver.
 
        Author:         E. Scott Daniels
        Date:           3 April 2019
 
        Author:         E. Scott Daniels
        Date:           3 April 2019
 #include <errno.h>
 #include <string.h>
 #include <stdint.h>
 #include <errno.h>
 #include <string.h>
 #include <stdint.h>
+#include <pthread.h>
+#include <semaphore.h>
 
 
-#include "../src/common/include/rmr.h"
-#include "../src/common/include/rmr_agnostic.h"
+#include "rmr.h"
+#include "rmr_agnostic.h"
 
 typedef struct entry_info {
        int group;
 
 typedef struct entry_info {
        int group;
@@ -44,6 +46,38 @@ typedef struct entry_info {
 } ei_t;
 
 
 } ei_t;
 
 
+/*
+       Driven by symtab foreach element of one space.
+       We count using the data as a counter.
+*/
+static void count_things( void* st, void* entry, char const* name, void* thing, void* vdata ) {
+       int* counter;
+
+       if( thing ) {
+               if( (counter = (int *) vdata) != NULL ) {
+                       *counter++;
+               }
+       }
+}
+
+/*
+       Returns the number of entries in the table for the given class.
+*/
+static int count_entries( route_table_t* rt, int class ) {
+       int counter = 0;
+
+       if( ! rt ) {
+               return 0;
+       }
+       if( !rt->hash ) {
+               return 0;
+       }
+
+       rmr_sym_foreach_class( rt->hash, class, count_things, &counter );       // run each and update counter
+
+       return counter;
+}
+
 /*
        This is the main route table test. It sets up a very specific table
        for testing (not via the generic setup function for other test
 /*
        This is the main route table test. It sets up a very specific table
        for testing (not via the generic setup function for other test
@@ -59,6 +93,8 @@ static int rt_test( ) {
        int errors = 0;                 // number errors found
        int     i;
        int k;
        int errors = 0;                 // number errors found
        int     i;
        int k;
+       int     c1;                                     // general counters
+       int c2;
        int mtype;
        int value;
        int alt_value;
        int mtype;
        int value;
        int alt_value;
@@ -75,8 +111,9 @@ static int rt_test( ) {
        nng_socket nn_sock;             // this is a struct in nng, so difficult to validate
 
        setenv( "ENV_VERBOSE_FILE", ".ut_rmr_verbose", 1 );                     // allow for verbose code in rtc to be driven
        nng_socket nn_sock;             // this is a struct in nng, so difficult to validate
 
        setenv( "ENV_VERBOSE_FILE", ".ut_rmr_verbose", 1 );                     // allow for verbose code in rtc to be driven
-       i = open( ".rmr_verbose", O_CREAT, 0664 );
+       i = open( ".ut_rmr_verbose", O_RDWR | O_CREAT, 0644 );
        if( i >= 0 ) {
        if( i >= 0 ) {
+               write( 1, "2\n", 2 );
                close( i );
        }
 
                close( i );
        }
 
@@ -141,8 +178,33 @@ static int rt_test( ) {
                }
        }
 
                }
        }
 
-       crt = uta_rt_clone( rt );
+       crt = uta_rt_clone( rt );                                                               // clone only the endpoint entries
        errors += fail_if_nil( crt, "cloned route table" );
        errors += fail_if_nil( crt, "cloned route table" );
+       if( crt ) {
+               c1 = count_entries( rt, 1 );
+               c2 = count_entries( crt, 1 );
+               errors += fail_not_equal( c1, c2, "cloned (endpoints) table entries space 1 count (b) did not match original table count (a)" );
+       
+               c2 = count_entries( crt, 0 );
+               errors += fail_not_equal( c2, 0, "cloned (endpoints) table entries space 0 count (a) was not zero as expected" );
+               uta_rt_drop( crt );
+       }
+
+
+       crt = uta_rt_clone_all( rt );                                                   // clone all entries
+       errors += fail_if_nil( crt, "cloned all route table" );
+
+       if( crt ) {
+               c1 = count_entries( rt, 0 );
+               c2 = count_entries( crt, 0 );
+               errors += fail_not_equal( c1, c2, "cloned (all) table entries space 0 count (b) did not match original table count (a)" );
+       
+               c1 = count_entries( rt, 1 );
+               c2 = count_entries( crt, 1 );
+               errors += fail_not_equal( c1, c2, "cloned (all) table entries space 1 count (b) did not match original table count (a)" );
+               uta_rt_drop( crt );
+       }
+       
 
        ep = uta_get_ep( rt, "localhost:4561" );
        errors += fail_if_nil( ep, "end point (fetch by name)" );
 
        ep = uta_get_ep( rt, "localhost:4561" );
        errors += fail_if_nil( ep, "end point (fetch by name)" );
@@ -197,8 +259,6 @@ static int rt_test( ) {
 
        uta_rt_drop( rt );
 
 
        uta_rt_drop( rt );
 
-       uta_rt_drop( crt );
-
        if( (ctx = (uta_ctx_t *) malloc( sizeof( uta_ctx_t ) )) != NULL ) {
                memset( ctx, 0, sizeof( *ctx ) );
 
        if( (ctx = (uta_ctx_t *) malloc( sizeof( uta_ctx_t ) )) != NULL ) {
                memset( ctx, 0, sizeof( *ctx ) );
 
@@ -218,14 +278,20 @@ static int rt_test( ) {
 
        uta_fib( "no-suhch-file" );                     // drive some error checking for coverage
 
 
        uta_fib( "no-suhch-file" );                     // drive some error checking for coverage
 
-/*
-       if( ctx ) {
-               if( ctx->rtg_addr ) {
-                       free( ctx->rtg_addr );
-               }
-               free( ctx );
-       }
-*/
+
+       ep = (endpoint_t *) malloc( sizeof( *ep ) );
+       pthread_mutex_init( &ep->gate, NULL );
+       ep->name = strdup( "worm" );
+       ep->addr = NULL;
+       state = uta_link2( ep );
+       errors += fail_if_true( state, "link2 did not return false when given nil pointers" );
+
+       state = uta_epsock_rr( rt, 122, 0, NULL, NULL );
+       errors += fail_if_true( state, "uta_epsock_rr returned bad state when given nil socket pointer" );
+
+       rt = uta_rt_init( );                                                                            // get us a route table
+       state = uta_epsock_rr( rt, 0, -1, NULL, &nn_sock );
+       errors += fail_if_true( state, "uta_epsock_rr returned bad state (true) when given negative group number" );
 
        return !!errors;                        // 1 or 0 regardless of count
 }
 
        return !!errors;                        // 1 or 0 regardless of count
 }