# squished to one.
release = Cherry
+2020 21 August; version 2.3.2
+ Small cleanup of "code smells" and add additional test stats
+ to unit tests.
+
2020 21 August; version 2.3.1
Fix bug in message introduced with "code smell" fix. (RIC-629)
set( major_version "2" ) # should be automatically populated from git tag later, but until CI process sets a tag we use this
set( minor_version "3" )
-set( patch_level "1" )
+set( patch_level "2" )
set( install_root "${CMAKE_INSTALL_PREFIX}" )
set( install_inc "include/ricxfcpp" )
Cherry Release
==============
+2020 21 August; version 2.3.2
+-----------------------------
+Small cleanup of "code smells" and add additional test stats
+to unit tests.
+
+
+2020 21 August; version 2.3.1
+-----------------------------
+Fix bug in message introduced with "code smell" fix.
+(RIC-629)
+
+
+2020 20 August; version 2.3.0
+-----------------------------
+Address sonar flagged "bugs" in the config class (RIC-629).
+
+
2020 13 August; version 2.2.2
-----------------------------
Correct potential memory leaks in xapp class (RIC-629)
#include <string.h>
#include <unistd.h>
#include <time.h>
+#include <iostream>
#include <rmr/RIC_message_types.h>
+
+#include "msg_component.hpp"
+#include "message.hpp"
+#include "alarm.hpp"
+
#ifndef RIC_ALARM
// this _should_ come from the message types header, but if not ensure we have something
constexpr int ric_alarm_value = 110;
#define RIC_ALARM ric_alarm_value
#endif
-#include <iostream>
-
-#include "msg_component.hpp"
-#include "message.hpp"
-#include "alarm.hpp"
-
extern const char* __progname; // runtime lib supplied since we don't get argv[0]
namespace xapp {
now()
);
- //action = std::string( wbuf );
return used;
}
ensure the object reference is cleaned up, and ensuring that the source
object references are removed.
*/
-Alarm& xapp::Alarm::operator=( Alarm&& soi ) {
+Alarm& xapp::Alarm::operator=( Alarm&& soi ) noexcept {
if( this != &soi ) { // cannot do self assignment
// anything that needs to be freed/delted from soi, must be done here
whid = new_whid;
}
-const void xapp::Alarm::Dump() {
+void xapp::Alarm::Dump() const {
fprintf( stderr, "Alarm: prob id: %d\n", problem_id );
fprintf( stderr, "Alarm: meid: %s\n", me_id.c_str() );
fprintf( stderr, "Alarm: app: %s\n", app_id.c_str() );
/*
Return the enpoint address string we have.
*/
-const std::string xapp::Alarm::Get_endpoint( ) {
+std::string xapp::Alarm::Get_endpoint( ) const {
return endpoint;
}
problem ID. Info and addional_info are user supplied data that is just passed
through.
*/
-bool xapp::Alarm::Raise( int new_severity, int problem, const std::string& info ) {
+bool xapp::Alarm::Raise( int new_severity, int problem, const std::string& cinfo ) {
Set_severity( new_severity );
problem_id = problem;
- this->info = info;
+ info = cinfo;
Raise();
}
-bool xapp::Alarm::Raise( int new_severity, int problem, const std::string& info, const std::string& additional_info ) {
+bool xapp::Alarm::Raise( int new_severity, int problem, const std::string& cinfo, const std::string& additional_info ) {
Set_severity( new_severity );
problem_id = problem;
- this->info = info;
+ info = cinfo;
this->add_info = additional_info;
Raise();
problem ID. Info and addional_info are user supplied data that is just passed
through.
*/
-bool xapp::Alarm::Clear( int new_severity, int problem, const std::string& info ) {
+bool xapp::Alarm::Clear( int new_severity, int problem, const std::string& cinfo ) {
Set_severity( new_severity );
problem_id = problem;
- this->info = info;
+ info = cinfo;
Clear();
}
-bool xapp::Alarm::Clear( int new_severity, int problem, const std::string& info, const std::string& additional_info ) {
+bool xapp::Alarm::Clear( int new_severity, int problem, const std::string& cinfo, const std::string& additional_info ) {
Set_severity( new_severity );
problem_id = problem;
- this->info = info;
+ info = cinfo;
this->add_info = additional_info;
Clear();
std::string app_id = ""; // application ID
int problem_id = -1; // problem ID (specific problem)
std::string severity = ""; // set_sev() xlates from SEV_* consts to collector's string values
- int action = 0; // ACT_* constants
std::string info = ""; // info string supplied by user
std::string add_info = ""; // additional information supplied by user
static const int ACT_CLEAR = 2;
static const int ACT_CLEAR_ALL = 3;
- Alarm( std::shared_ptr<Message> msg ); // builders
+ explicit Alarm( std::shared_ptr<Message> msg ); // builders
Alarm( std::shared_ptr<Message> msg, const std::string& meid );
Alarm( std::shared_ptr<Message> msg, int prob_id, const std::string& meid );
Alarm( const Alarm& soi ); // copy to newly created instance
Alarm& operator=( const Alarm& soi ); // copy operator
Alarm( Alarm&& soi ); // mover
- Alarm& operator=( Alarm&& soi ); // move operator
+ Alarm& operator=( Alarm&& soi ) noexcept; // move operator
~Alarm(); // destroyer
- const std::string Get_endpoint( );
+ std::string Get_endpoint( ) const;
void Set_additional( const std::string& new_info );
void Set_appid( const std::string& new_id );
bool Clear_all( );
- const void Dump();
+ void Dump() const;
};
} // namespace
*tok = 0;
bname = strdup( tok+1 );
} else {
- free( dname );
+ delete dname;
dname = strdup( "." );
bname = strdup( fname.c_str() );
}
wfd = inotify_add_watch( ifd, dname, IN_MOVED_TO | IN_CLOSE_WRITE ); // we only care about close write changes
- free( dname );
+ delete dname;
if( wfd < 0 ) {
fprintf( stderr, "<XFCPP> ### ERR ### unable to add watch on config file %s: %s\n", fname.c_str(), strerror( errno ) );
}
jh->Unset_blob();
- if( jh->Set_blob( (const char *) "controls" ) ) {
- if( jh->Exists( name.c_str() ) ) {
- value = jh->String( name.c_str() );
- if( value.compare( "" ) != 0 ) {
- rv = value;
- }
+ if( jh->Set_blob( (const char *) "controls" ) && jh->Exists( name.c_str() ) ) {
+ value = jh->String( name.c_str() );
+ if( value.compare( "" ) != 0 ) {
+ rv = value;
}
}
set_test_name( "metrics_test" );
x = std::shared_ptr<Xapp>( new Xapp( "4560", true ) );
- if( x == NULL ) {
- fprintf( stderr, "<FAIL> unable to allocate xapp object\n" );
+ if( fail_if( x == NULL, "could not allocate new xapp" ) ) {
announce_results( 1 );
return 1;
}
m = x->Alloc_metrics( );
+ if( fail_if( m == NULL, "could not allocate a metric object" ) ) {
+ announce_results( errors );
+ return errors;
+ }
+
m->Push_data( "barney_balance", 216.49 );
m->Push_data( "fred_balance", 760.88 );
m->Send( );
// drive alternate builders
m = x->Alloc_metrics( "different-source" );
+ if( fail_if( m == NULL, "could not allocate a metric object" ) ) {
+ announce_results( errors );
+ return errors;
+ }
+
m->Push_data( "wilma_balance", 1986.0430 );
m->Send();
m = x->Alloc_metrics( "different-app", "different-source" );
+ if( fail_if( m == NULL, "could not allocate a metric object" ) ) {
+ announce_results( errors );
+ return errors;
+ }
+
m->Push_data( "wilma_balance", 1986.0430 );
m->Push_data( "pebbles_balance", 1982.0614 );
m->Send();
do
./$x >/tmp/PID$$.log 2>&1
abort_if_error $? "test failed: $x"
+ grep SUMMARY /tmp/PID$$.log
done
# it seems that we loose coverage reporting if metrics_test's gcov file is generated
#include <string>
static std::string test_name = "unknown";
+static int ut_tests_driven = 0;
+
+// -------------------------------------------------------------------------------
/*
Set the name of the current tester
Returns 1 if the condition is true (not zero)
*/
extern int fail_if( int cond, std::string reason ) {
+ ut_tests_driven++;
+
if( cond ) {
fprintf( stderr, "<FAIL> %s: %s\n", test_name.c_str(), reason.c_str() );
return 1;
Returns 1 if the condition is false.
*/
extern int fail_if_false( int cond, std::string reason ) {
+ ut_tests_driven++;
+
if( !cond ) {
fprintf( stderr, "<FAIL> %s: %s\n", test_name.c_str(), reason.c_str() );
return 1;
}
extern void announce_results( int errors ) {
+ fprintf( stderr, "<SUMMARY> %s %d tests drivn, %d passed, %d failed\n",
+ test_name.c_str(), ut_tests_driven, ut_tests_driven - errors, errors );
+
if( errors > 0 ) {
fprintf( stderr, "<FAIL> %s: failed with %d errors\n", test_name.c_str(), errors );
} else {