Reorganise the sidecars
[ric-app/mc.git] / sidecars / listener / unit_test.c
1 // vim: ts=4 sw=4 noet:
2 /*
3  --------------------------------------------------------------------------------
4         Copyright (c) 2018-2019 AT&T Intellectual Property.
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10            http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17  --------------------------------------------------------------------------------
18 */
19
20 /*
21         Mnemonic:       unit_test.c
22         Abstract:       Basic unit tests for the mc listener.
23         Date:           22 August 2019
24         Author:         E. Scott Daniels
25 */
26
27 // this/these are what we are testing; include them directly
28 #include "mcl.c"
29
30 /*
31         Parms:  [fifo-dir-name]
32 */
33 int main( int argc,  char** argv ) {
34         void*   ctx;
35         int             errors;
36         char*   dname = "/tmp/fifos";
37         char*   port = "4560";
38         int             fd;
39         int             fd2;
40
41         if( argc > 1 ) {
42                 dname = argv[1];
43         }
44         
45         ctx = mcl_mk_context( dname );
46         if( ctx == NULL ) {
47                 fprintf( stderr, "[FAIL] couldn't make context" );
48                 exit( 1 );
49         }
50
51         mcl_set_sigh();                 // prevent colobber from broken pipe
52
53         fd = suss_fifo( ctx, 101, 1 );                          // should open the file for writing and return the fdes
54         if( fd < 0 ) {
55                 fprintf( stderr, "[FAIL] suss_fifo did not return a valid fd\n" );
56                 errors++;
57         }
58
59         fd2= suss_fifo( ctx, 101, 0 );                          // should open the file file for reading and return a different fd
60         if( fd < 0 ) {
61                 fprintf( stderr, "[FAIL] suss_fifo did not return a valid fd\n" );
62                 errors++;
63         }
64         if( fd == fd2 ) {
65                 fprintf( stderr, "[FAIL] reading and writing fifo file descriptors expected to differ; both were %d\n", fd );
66                 errors++;
67         }
68
69         mcl_start_listening( ctx, port, 0 );                    // start the listener, no waiting for rt since we don't send
70
71         if( ! errors ) {
72                 fprintf( stderr, "[PASS] all tests look peachy\n" );
73         }
74
75         return errors != 0;
76 }
77