1 // vim: ts=4 sw=4 noet :
3 ==================================================================================
4 Copyright (c) 2020 Nokia
5 Copyright (c) 2020 AT&T Intellectual Property.
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
11 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
22 Mnemonic: metric_test.cpp
23 Abstract: This is the unit test driver for the metrics class.
26 Author: E. Scott Daniels
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"
47 #include "../src/metrics/metrics.hpp" // overtly pull the code under test to get coverage opts
48 #include "../src/messaging/messenger.cpp"
49 #include "../src/metrics/metrics.cpp"
51 #include "ut_support.cpp"
53 int main( int argc, char** argv ) {
55 std::shared_ptr<Xapp> x;
56 std::shared_ptr<xapp::Metrics> m;
58 set_test_name( "metrics_test" );
60 x = std::shared_ptr<Xapp>( new Xapp( "4560", true ) );
62 fprintf( stderr, "<FAIL> unable to allocate xapp object\n" );
63 announce_results( 1 );
67 m = x->Alloc_metrics( );
68 m->Push_data( "barney_balance", 216.49 );
69 m->Push_data( "fred_balance", 760.88 );
72 // ensure data is cleared after first send
73 m->Push_data( "barney_balance", 216.49 );
74 m->Push_data( "fred_balance", 760.88 );
75 m->Push_data( "wilma_balance", 1986.0430 );
78 m->Send(); // shouldn't really send
81 // drive alternate builders
82 m = x->Alloc_metrics( "different-source" );
83 m->Push_data( "wilma_balance", 1986.0430 );
86 m = x->Alloc_metrics( "different-app", "different-source" );
87 m->Push_data( "wilma_balance", 1986.0430 );
88 m->Push_data( "pebbles_balance", 1982.0614 );
92 m->Set_reporter( "set-reporter" );
93 m->Set_source( "set-source" );
96 // drive move/copy adjunct functions
98 xapp::Metrics b = *m.get(); // force the move/copy operator functions to trigger
99 xapp::Metrics c( NULL ); // a useless metric without a message
100 xapp::Metrics f( NULL, "source" ); // a useless metric to drive direct construction
101 c = *m.get(); // drive copy = operator
103 b = std::move( c ); // move = operator
104 xapp::Metrics d = std::move( b ); // move constructor
107 // ---------------------------- end housekeeping ---------------------------
108 announce_results( errors );