blob: 1999dc7c3603ef633c201976f7ecc1b6ef445090 [file] [log] [blame]
E. Scott Danielsef362052020-07-22 15:49:54 -04001// vim: ts=4 sw=4 noet :
2/*
3==================================================================================
4 Copyright (c) 2020 Nokia
5 Copyright (c) 2020 AT&T Intellectual Property.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18==================================================================================
19*/
20
21/*
22 Mnemonic: metric_test.cpp
23 Abstract: This is the unit test driver for the metrics class.
24
25 Date: 20 July 2020
26 Author: E. Scott Daniels
27*/
28
29#include <errno.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <unistd.h>
33#include <fcntl.h>
34#include <string.h>
35
36#include <string>
37#include <memory>
38
39#include "../src/messaging/callback.hpp"
40#include "../src/messaging/default_cb.hpp"
41#include "../src/messaging/message.hpp"
42#include "../src/messaging/messenger.hpp"
43#include "../src/messaging/msg_component.hpp"
44#include "../src/alarm/alarm.hpp"
45#include "../src/xapp/xapp.hpp"
46
47#include "../src/metrics/metrics.hpp" // overtly pull the code under test to get coverage opts
E. Scott Danielsd486a172020-07-29 12:39:54 -040048#include "../src/messaging/messenger.cpp"
E. Scott Danielsef362052020-07-22 15:49:54 -040049#include "../src/metrics/metrics.cpp"
50
51#include "ut_support.cpp"
52
53int main( int argc, char** argv ) {
54 int errors = 0;
55 std::shared_ptr<Xapp> x;
56 std::shared_ptr<xapp::Metrics> m;
57
E. Scott Danielsd486a172020-07-29 12:39:54 -040058 set_test_name( "metrics_test" );
E. Scott Danielsef362052020-07-22 15:49:54 -040059
60 x = std::shared_ptr<Xapp>( new Xapp( "4560", true ) );
E. Scott Daniels23d0e612020-09-17 15:46:48 -040061 if( fail_if( x == NULL, "could not allocate new xapp" ) ) {
E. Scott Danielsef362052020-07-22 15:49:54 -040062 announce_results( 1 );
63 return 1;
64 }
65
66 m = x->Alloc_metrics( );
E. Scott Daniels23d0e612020-09-17 15:46:48 -040067 if( fail_if( m == NULL, "could not allocate a metric object" ) ) {
68 announce_results( errors );
69 return errors;
70 }
71
E. Scott Danielsef362052020-07-22 15:49:54 -040072 m->Push_data( "barney_balance", 216.49 );
73 m->Push_data( "fred_balance", 760.88 );
74 m->Send( );
75
76 // ensure data is cleared after first send
77 m->Push_data( "barney_balance", 216.49 );
78 m->Push_data( "fred_balance", 760.88 );
79 m->Push_data( "wilma_balance", 1986.0430 );
80 m->Send();
81
82 m->Send(); // shouldn't really send
83
84
85 // drive alternate builders
86 m = x->Alloc_metrics( "different-source" );
E. Scott Daniels23d0e612020-09-17 15:46:48 -040087 if( fail_if( m == NULL, "could not allocate a metric object" ) ) {
88 announce_results( errors );
89 return errors;
90 }
91
E. Scott Danielsef362052020-07-22 15:49:54 -040092 m->Push_data( "wilma_balance", 1986.0430 );
93 m->Send();
94
95 m = x->Alloc_metrics( "different-app", "different-source" );
E. Scott Daniels23d0e612020-09-17 15:46:48 -040096 if( fail_if( m == NULL, "could not allocate a metric object" ) ) {
97 announce_results( errors );
98 return errors;
99 }
100
E. Scott Danielsef362052020-07-22 15:49:54 -0400101 m->Push_data( "wilma_balance", 1986.0430 );
102 m->Push_data( "pebbles_balance", 1982.0614 );
103 m->Send();
104
105
106 m->Set_reporter( "set-reporter" );
107 m->Set_source( "set-source" );
108
109
110 // drive move/copy adjunct functions
111
112 xapp::Metrics b = *m.get(); // force the move/copy operator functions to trigger
113 xapp::Metrics c( NULL ); // a useless metric without a message
114 xapp::Metrics f( NULL, "source" ); // a useless metric to drive direct construction
115 c = *m.get(); // drive copy = operator
116
117 b = std::move( c ); // move = operator
118 xapp::Metrics d = std::move( b ); // move constructor
119
120
121 // ---------------------------- end housekeeping ---------------------------
122 announce_results( errors );
123 return !!errors;
124}