Merge branch 'master' into 1599-update-the-workflow-for-centos-7

This commit is contained in:
Hong Chen 2023-10-26 10:59:02 -05:00
commit 19bdb0c527
21 changed files with 264 additions and 114 deletions

View File

@ -21,6 +21,7 @@ typedef struct _LQUEUE
LQUEUE* LQ_Create(void); /* create and initialize a LQUEUE */ LQUEUE* LQ_Create(void); /* create and initialize a LQUEUE */
int LQ_Delete(LQUEUE* lqueue); /* free an lqueue object created by LQ_Create.*/
void LQ_Init(LQUEUE*); /* initialize a LQUEUE */ void LQ_Init(LQUEUE*); /* initialize a LQUEUE */

View File

@ -200,19 +200,11 @@ PlotViewNode::PlotViewNode( Widget Toplevel, Widget Parent_form, DPC_plot* Plot
curves = new XYCurve[n_curves]; curves = new XYCurve[n_curves];
// X Axis label. // X Axis label.
if ((const_temp_str = plot->getXLabel()) != NULL) { snprintf( charbuf, sizeof(charbuf), "%s", const_temp_str );
snprintf( charbuf, sizeof(charbuf), "%s", const_temp_str );
} else {
charbuf[0] = '\0';
}
X_label = XmStringCreateLocalized( charbuf); X_label = XmStringCreateLocalized( charbuf);
// Y Axis label. // Y Axis label.
if ((const_temp_str = plot->getYLabel()) != NULL) { snprintf( charbuf, sizeof(charbuf), "%s", const_temp_str );
snprintf( charbuf, sizeof(charbuf), "%s", const_temp_str );
} else {
charbuf[0] = '\0';
}
Y_label = XmStringCreateLocalized( charbuf); Y_label = XmStringCreateLocalized( charbuf);
// --------------------------- // ---------------------------

View File

@ -319,15 +319,14 @@ TableViewNode::TableViewNode( Widget Toplevel, DPC_table* Table, int Xpos, int Y
// Print out the column heading labels. // Print out the column heading labels.
// ---------------------------------------------------------------- // ----------------------------------------------------------------
for (colix=0; colix < n_columns ; colix++) { for (colix=0; colix < n_columns ; colix++) {
const char *column_label = table->getColumnLabel( colix); std::string column_label = table->getColumnLabel(colix);
if (column_label.empty()) {
if (!column_label) {
snprintf( charbuf, sizeof(charbuf), "Column_%d", colix); snprintf( charbuf, sizeof(charbuf), "Column_%d", colix);
table_text_buf = twprint( table_text_buf, &table_buf_size, &table_insertion_pos, table_text_buf = twprint( table_text_buf, &table_buf_size, &table_insertion_pos,
column_heading_format[colix], charbuf); column_heading_format[colix], charbuf);
} else { } else {
table_text_buf = twprint( table_text_buf, &table_buf_size, &table_insertion_pos, table_text_buf = twprint( table_text_buf, &table_buf_size, &table_insertion_pos,
column_heading_format[colix], column_label); column_heading_format[colix], column_label.c_str());
} }
} }
table_text_buf = twprint( table_text_buf, &table_buf_size, &table_insertion_pos, (char *)"\n"); table_text_buf = twprint( table_text_buf, &table_buf_size, &table_insertion_pos, (char *)"\n");

View File

@ -124,11 +124,11 @@ void GPViewPlotNode::finalize() {
* So, check the return value before making the assignment. * So, check the return value before making the assignment.
*/ */
plot_title = (plot->getTitle()) ? plot->getTitle() : tmp_stream.str(); plot_title = (plot->getTitle()) ? plot->getTitle() : tmp_stream.str();
plot_x_label = (plot->getXLabel()) ? plot->getXLabel() : ""; plot_x_label = plot->getXLabel();
plot_x_scale = (plot->getAttribute("x_scale")) ? plot->getAttribute("x_scale") : ""; plot_x_scale = (plot->getAttribute("x_scale")) ? plot->getAttribute("x_scale") : "";
plot_x_min_rng = (plot->getAttribute("xmin")) ? plot->getAttribute("xmin") : ""; plot_x_min_rng = (plot->getAttribute("xmin")) ? plot->getAttribute("xmin") : "";
plot_x_max_rng = (plot->getAttribute("xmax")) ? plot->getAttribute("xmax") : ""; plot_x_max_rng = (plot->getAttribute("xmax")) ? plot->getAttribute("xmax") : "";
plot_y_label = (plot->getYLabel()) ? plot->getYLabel() : ""; plot_y_label = plot->getYLabel();
plot_y_format = (plot->getAttribute("format")) ? plot->getAttribute("format") : ""; plot_y_format = (plot->getAttribute("format")) ? plot->getAttribute("format") : "";
plot_y_scale = (plot->getAttribute("y_scale")) ? plot->getAttribute("y_scale") : ""; plot_y_scale = (plot->getAttribute("y_scale")) ? plot->getAttribute("y_scale") : "";
plot_y_min_rng = (plot->getAttribute("ymin")) ? plot->getAttribute("ymin") : ""; plot_y_min_rng = (plot->getAttribute("ymin")) ? plot->getAttribute("ymin") : "";

View File

@ -11,8 +11,8 @@ DPC_UnitConvDataStream::DPC_UnitConvDataStream(DataStream* ds, const char *ToUni
ut_unit * to = NULL ; ut_unit * to = NULL ;
ut_unit * from = NULL ; ut_unit * from = NULL ;
const char * recorded_units = ds->getUnit().c_str(); std::string recorded_units = ds->getUnit();
source_ds = ds; source_ds = ds;
@ -24,7 +24,7 @@ DPC_UnitConvDataStream::DPC_UnitConvDataStream(DataStream* ds, const char *ToUni
// If the user has specified a units conversion and those units are valid ... // If the user has specified a units conversion and those units are valid ...
if ( to != NULL ) { if ( to != NULL ) {
// If the recorded data file doesn't contain the units in which the data is recorded ... // If the recorded data file doesn't contain the units in which the data is recorded ...
if ((recorded_units == NULL) || (strcmp(recorded_units,"") == 0)) { if (recorded_units.empty()) {
// If the user didn't give us a hint as to what the units are (using var@from_units) ... // If the user didn't give us a hint as to what the units are (using var@from_units) ...
if ((FromUnitsHint == NULL) || (strcmp(FromUnitsHint,"") == 0)) { if ((FromUnitsHint == NULL) || (strcmp(FromUnitsHint,"") == 0)) {
// set the from units to the same as the to units. // set the from units to the same as the to units.
@ -47,7 +47,7 @@ DPC_UnitConvDataStream::DPC_UnitConvDataStream(DataStream* ds, const char *ToUni
} }
} else { // the recorded data file does "know" the units in which the data was recorded, } else { // the recorded data file does "know" the units in which the data was recorded,
// so those will be the units that we convert from. // so those will be the units that we convert from.
from = ut_parse(u_system, recorded_units, UT_ASCII) ; from = ut_parse(u_system, recorded_units.c_str(), UT_ASCII) ;
if ( !from ) { if ( !from ) {
std::cerr << "ERROR: Unable to to perform units conversion because the" std::cerr << "ERROR: Unable to to perform units conversion because the"
<< " units in the data recording file appear to be corrupt." << " units in the data recording file appear to be corrupt."
@ -72,7 +72,7 @@ DPC_UnitConvDataStream::DPC_UnitConvDataStream(DataStream* ds, const char *ToUni
} }
} else { // The user has not specified a units conversion or the units were not valid. } else { // The user has not specified a units conversion or the units were not valid.
// If the recorded data file doesn't contain the units in which the data is recorded ... // If the recorded data file doesn't contain the units in which the data is recorded ...
if ((recorded_units == NULL) || (strcmp(recorded_units,"") == 0)) { if (recorded_units.empty()) {
// If the user didn't give us a hint as to what the units are (using var@from_units) ... // If the user didn't give us a hint as to what the units are (using var@from_units) ...
if ((FromUnitsHint == NULL) || (strcmp(FromUnitsHint,"") == 0)) { if ((FromUnitsHint == NULL) || (strcmp(FromUnitsHint,"") == 0)) {
cf = cv_get_trivial() ; cf = cv_get_trivial() ;

View File

@ -39,7 +39,7 @@ public:
/** /**
* Return the name of the X variable. * Return the name of the X variable.
*/ */
const char *getXVarShortName() { std::string getXVarShortName() {
return( x_var->getShortName() ); return( x_var->getShortName() );
}; };
@ -53,7 +53,7 @@ public:
/** /**
* Return the name of the Y variable. * Return the name of the Y variable.
*/ */
const char *getYVarShortName() { std::string getYVarShortName() {
return( y_var->getShortName() ); return( y_var->getShortName() );
}; };

View File

@ -78,16 +78,16 @@ public:
} }
/** /**
* Return the X-axis label of the plot, which may be NULL. * Return the X-axis label of the plot, which may be empty.
*/ */
const char *getXLabel() { std::string getXLabel() {
return( relation->getXAxisLabel()); return( relation->getXAxisLabel());
} }
/** /**
* Return the Y-axis label of the plot, which may be NULL. * Return the Y-axis label of the plot, which may be empty.
*/ */
const char *getYLabel() { std::string getYLabel() {
return( relation->getYAxisLabel()); return( relation->getYAxisLabel());
} }

View File

@ -106,9 +106,9 @@ DPC_std_curve::DPC_std_curve(
Time_constraints ); Time_constraints );
if (ds[0] != NULL) { if (ds[0] != NULL) {
const char* ds_units = ds[0]->getUnit().c_str(); std::string ds_units = ds[0]->getUnit();
y_actual_units = strdup(ds_units); y_actual_units = strdup(ds_units.c_str());
// Tell our DataStream to start at the beginning. // Tell our DataStream to start at the beginning.
ds[0]->begin(); ds[0]->begin();

View File

@ -194,12 +194,12 @@ int DPC_table::getNumColumns() {
} }
// MEMBER FUNCTION // MEMBER FUNCTION
const char *DPC_table::getColumnLabel(unsigned int index) { std::string DPC_table::getColumnLabel(unsigned int index) {
DPM_column *column = table_spec->getColumn( index ); DPM_column *column = table_spec->getColumn( index );
if ( column->getLabel() != NULL) { if ( column->getLabel() != NULL) {
return( column->getLabel()); return( column->getLabel());
} else { } else {
return( column->getVar()->getShortName()); return( column->getVar()->getShortName() );
} }
} }

View File

@ -53,9 +53,9 @@ public:
int getNumColumns(); int getNumColumns();
/** /**
* Return the Label (which may be NULL) of the of the indicated column. * Return the Label (which may be empty) of the of the indicated column.
*/ */
const char *getColumnLabel(unsigned int index); std::string getColumnLabel(unsigned int index);
/** /**
* Return the name of the variable for the indicated column. * Return the name of the variable for the indicated column.

View File

@ -231,57 +231,54 @@ const char * DPM_curve::getZVarName(unsigned int case_index) {
} }
// MEMBER FUNCTION // MEMBER FUNCTION
const char * DPM_curve::getXCommonName() { std::string DPM_curve::getXCommonName() {
const char *candidate_label; std::string candidate_label;
const char *short_name;
int n_vars, i; int n_vars, i;
candidate_label = x_varcase_list[0]->getShortName(); candidate_label = x_varcase_list[0]->getShortName();
n_vars = (int)x_varcase_list.size(); n_vars = (int)x_varcase_list.size();
for (i=1; i<n_vars; i++) { for (i=1; i<n_vars; i++) {
short_name = x_varcase_list[i]->getShortName(); if (candidate_label != x_varcase_list[i]->getShortName()) {
if (strcmp( candidate_label, short_name) != 0 ) { return ("");
return (NULL);
} }
} }
return ( candidate_label); return (candidate_label);
} }
// MEMBER FUNCTION // MEMBER FUNCTION
const char * DPM_curve::getYCommonName() { std::string DPM_curve::getYCommonName() {
const char *candidate_label; std::string candidate_label;
const char *short_name;
int n_vars, i; int n_vars, i;
candidate_label = y_varcase_list[0]->getShortName(); candidate_label = y_varcase_list[0]->getShortName();
n_vars = (int)y_varcase_list.size(); n_vars = (int)y_varcase_list.size();
for (i=1; i<n_vars; i++) { for (i=1; i<n_vars; i++) {
short_name = y_varcase_list[i]->getShortName(); if (candidate_label != y_varcase_list[i]->getShortName()) {
if (strcmp( candidate_label, short_name) != 0 ) { return ("");
return (NULL);
} }
} }
return ( candidate_label); return ( candidate_label);
} }
// MEMBER FUNCTION // MEMBER FUNCTION
const char * DPM_curve::getZCommonName() { std::string DPM_curve::getZCommonName() {
const char *candidate_label; std::string candidate_label;
const char *short_name;
int n_vars, i; int n_vars, i;
candidate_label = z_varcase_list[0]->getShortName(); candidate_label = z_varcase_list[0]->getShortName();
n_vars = (int)z_varcase_list.size(); n_vars = (int)z_varcase_list.size();
for (i=1; i<n_vars; i++) { for (i=1; i<n_vars; i++) {
short_name = z_varcase_list[i]->getShortName(); if (candidate_label != z_varcase_list[i]->getShortName()) {
if (strcmp( candidate_label, short_name) != 0 ) { return ("");
return (NULL);
} }
} }
return ( candidate_label); return (candidate_label);
} }
// MEMBER FUNCTION // MEMBER FUNCTION

View File

@ -69,17 +69,17 @@ public:
/** /**
* *
*/ */
const char * getXCommonName(); std::string getXCommonName();
/** /**
* *
*/ */
const char * getYCommonName(); std::string getYCommonName();
/** /**
* *
*/ */
const char * getZCommonName(); std::string getZCommonName();
/** /**
* Output an xml representation of DPM_curve. * Output an xml representation of DPM_curve.

View File

@ -148,90 +148,81 @@ int DPM_relation::NumberOfAxes() {
} }
// MEMBER FUNCTION // MEMBER FUNCTION
const char * DPM_relation::getXAxisLabel() { std::string DPM_relation::getXAxisLabel() {
const char * candidate_label; std::string candidate_label;
const char * short_name;
int n_curves, i; int n_curves, i;
if (xaxis) { if (xaxis) {
candidate_label = xaxis->getLabel(); candidate_label = xaxis->getLabel();
} else { } else {
candidate_label = NULL; candidate_label = "";
} }
// If an Y-Axis label wasn't supplied, see if there is a common // If an Y-Axis label wasn't supplied, see if there is a common
// variable name that will serve as a label. // variable name that will serve as a label.
if (candidate_label == NULL) { if (candidate_label == "") {
if (( candidate_label = curve_list[0]->getXCommonName() ) == NULL) { if (( candidate_label = curve_list[0]->getXCommonName() ) == "") {
return (NULL); return ("");
} }
n_curves = (int)curve_list.size(); n_curves = (int)curve_list.size();
for (i=1; i<n_curves; i++) { for (i=1; i<n_curves; i++) {
if (( short_name = curve_list[i]->getXCommonName() ) == NULL ) { if ( curve_list[i]->getXCommonName().empty() || candidate_label != curve_list[i]->getXCommonName()) {
return (NULL); return ("");
} }
if (strcmp( candidate_label, short_name) != 0 ) {
return (NULL);
}
} }
} }
return (candidate_label); return (candidate_label);
} }
// MEMBER FUNCTION // MEMBER FUNCTION
const char * DPM_relation::getYAxisLabel() { std::string DPM_relation::getYAxisLabel() {
const char * candidate_label; std::string candidate_label;
const char * short_name;
int n_curves, i; int n_curves, i;
if (yaxis) { if (yaxis) {
candidate_label = yaxis->getLabel(); candidate_label = yaxis->getLabel();
} else { } else {
candidate_label = NULL; candidate_label = "";
} }
// If an Y-Axis label wasn't supplied, see if there is a common // If an Y-Axis label wasn't supplied, see if there is a common
// variable name that will serve as a label. // variable name that will serve as a label.
if (candidate_label == NULL) { if (candidate_label == "") {
if (( candidate_label = curve_list[0]->getYCommonName() ) == NULL) { if (( candidate_label = curve_list[0]->getYCommonName() ) == "") {
return (NULL); return ("");
} }
n_curves = (int)curve_list.size(); n_curves = (int)curve_list.size();
for (i=1; i<n_curves; i++) { for (i=1; i<n_curves; i++) {
if (( short_name = curve_list[i]->getYCommonName() ) == NULL ) { if (curve_list[i]->getYCommonName().empty() || candidate_label != curve_list[i]->getYCommonName()) {
return (NULL); return ("");
} }
if (strcmp( candidate_label, short_name) != 0 ) {
return (NULL);
}
} }
} }
return (candidate_label); return (candidate_label);
} }
// MEMBER FUNCTION // MEMBER FUNCTION
const char * DPM_relation::getZAxisLabel() { std::string DPM_relation::getZAxisLabel() {
const char * candidate_label; std::string candidate_label;
const char * short_name;
int n_curves, i; int n_curves, i;
if (zaxis) { if (zaxis) {
candidate_label = zaxis->getLabel(); candidate_label = zaxis->getLabel();
} else { } else {
candidate_label = NULL; candidate_label = "";
} }
// If an Z-Axis label wasn't supplied, see if there is a common // If an Z-Axis label wasn't supplied, see if there is a common
// variable name that will serve as a label. // variable name that will serve as a label.
if (candidate_label == NULL) { if (candidate_label == "") {
if (( candidate_label = curve_list[0]->getZCommonName() ) == NULL) { if (( candidate_label = curve_list[0]->getZCommonName() ) == "") {
return (NULL); return ("");
} }
n_curves = (int)curve_list.size(); n_curves = (int)curve_list.size();
for (i=1; i<n_curves; i++) { for (i=1; i<n_curves; i++) {
if (( short_name = curve_list[i]->getZCommonName() ) == NULL ) { if (curve_list[i]->getZCommonName().empty() || candidate_label != curve_list[i]->getZCommonName()) {
return (NULL); return ("");
} }
if (strcmp( candidate_label, short_name) != 0 ) {
return (NULL);
}
} }
} }
return (candidate_label); return (candidate_label);

View File

@ -53,9 +53,9 @@ public:
/** /**
* *
*/ */
const char * getXAxisLabel(); std::string getXAxisLabel();
const char * getYAxisLabel(); std::string getYAxisLabel();
const char * getZAxisLabel(); std::string getZAxisLabel();
/** /**
* *

View File

@ -40,7 +40,7 @@ const char* DPM_var::getName() {
return ( (const char*)name ); return ( (const char*)name );
} }
const char* DPM_var::getShortName() { std::string DPM_var::getShortName() {
char *p; char *p;
std::string::size_type idx ; std::string::size_type idx ;
@ -103,7 +103,7 @@ const char* DPM_var::getShortName() {
} else { } else {
combinedName += " - " + paramName2; combinedName += " - " + paramName2;
} }
return combinedName.c_str(); return combinedName;
} }
} }

View File

@ -43,7 +43,7 @@ class DPM_var:public DPM_component {
* Return the part of the variable name right of the last * Return the part of the variable name right of the last
* period or the name if there are no periods. * period or the name if there are no periods.
*/ */
const char *getShortName(); std::string getShortName();
/** /**
* Output an xml representation of DPM_var. * Output an xml representation of DPM_var.

View File

@ -93,7 +93,7 @@ DPV_pointer test_view::create_table_view( DPV_pointer parent_data,
cout << "Number of Columns : " << n_columns << endl; cout << "Number of Columns : " << n_columns << endl;
for (colix=0; colix < n_columns ; colix++) { for (colix=0; colix < n_columns ; colix++) {
const char *col_label = table->getColumnLabel( colix); const char *col_label = table->getColumnLabel( colix).c_str();
const char *var_name = table->getColumnVarName( colix); const char *var_name = table->getColumnVarName( colix);
const char *col_units = table->getColumnUnits( colix); const char *col_units = table->getColumnUnits( colix);
const char *format = table->getColumnAttribute( colix,"format"); const char *format = table->getColumnAttribute( colix,"format");

View File

@ -138,7 +138,7 @@ DPV_pointer Test_view::render_table( DPV_pointer parent_data, DPC_table *table)
s << "Number of Columns: " << n_columns << std::endl; s << "Number of Columns: " << n_columns << std::endl;
for (colix=0; colix < n_columns ; colix++) { for (colix=0; colix < n_columns ; colix++) {
if ((temp_cstr = table->getColumnLabel(colix)) != NULL) { if ((temp_cstr = table->getColumnLabel(colix).c_str())[0] != '\0') {
s << "Column Label [" << colix << "]: " << temp_cstr << std::endl; s << "Column Label [" << colix << "]: " << temp_cstr << std::endl;
} }
if ((temp_cstr = table->getColumnVarName(colix)) != NULL) { if ((temp_cstr = table->getColumnVarName(colix)) != NULL) {

View File

@ -16,11 +16,24 @@ LQUEUE *LQ_Create(void)
return ret; return ret;
} }
int LQ_Delete(LQUEUE* lqueue) {
if (lqueue == NULL) {
fprintf(stderr, "Error (%s): Pointer to LQUEUE is NULL.\n", __FUNCTION__ );
fflush(stderr);
return -1;
}
DLL_Delete(&lqueue->list);
return 0;
}
/* initialize a queue created statically */ /* initialize a queue created statically */
void LQ_Init(LQUEUE * pQueue) void LQ_Init(LQUEUE * pQueue)
{ {
if (pQueue == NULL) {
fprintf(stderr, "Error (%s): Pointer to LQUEUE is NULL.\n", __FUNCTION__ );
fflush(stderr);
}
DLL_Init(&(pQueue->list)); DLL_Init(&(pQueue->list));
} }
@ -31,7 +44,7 @@ void LQ_EnQ(void *pData, LQUEUE * pQueue)
{ {
if (pQueue == NULL) { if (pQueue == NULL) {
fprintf(stderr, "Queue is NULL"); fprintf(stderr, "Error (%s): Pointer to LQUEUE is NULL.", __FUNCTION__ );
return; return;
} }
@ -43,8 +56,14 @@ void LQ_EnQ(void *pData, LQUEUE * pQueue)
void *LQ_DeQ(LQUEUE * pQueue) void *LQ_DeQ(LQUEUE * pQueue)
{ {
if (LQ_GetCount(pQueue) > 0) if (pQueue == NULL) {
fprintf(stderr, "Error (%s): Pointer to LQUEUE is NULL.", __FUNCTION__ );
return NULL;
}
if (LQ_GetCount(pQueue) > 0) {
return DLL_RemoveAt(DLL_GetTailPosition(&(pQueue->list)), &(pQueue->list)); return DLL_RemoveAt(DLL_GetTailPosition(&(pQueue->list)), &(pQueue->list));
}
return NULL; return NULL;
} }
@ -53,15 +72,19 @@ void *LQ_DeQ(LQUEUE * pQueue)
void *LQ_Peek(LQUEUE * pQueue) void *LQ_Peek(LQUEUE * pQueue)
{ {
if (pQueue == NULL) {
if (pQueue == NULL && DLL_GetCount(&(pQueue->list)) <= 0) { fprintf(stderr, "Error (%s): Pointer to LQUEUE is NULL.", __FUNCTION__);
fprintf(stderr, "Queue is NULL and number of elements is 0"); fflush(stderr);
return NULL; return NULL;
} }
if (pQueue != NULL) if ( DLL_GetCount( &(pQueue->list)) <= 0) {
return DLL_GetAt(DLL_GetTailPosition(&(pQueue->list)), &(pQueue->list)); fprintf(stderr, "Error (%s): LQUEUE is empty.", __FUNCTION__);
return NULL; fflush(stderr);
return NULL;
}
return DLL_GetAt(DLL_GetTailPosition(&(pQueue->list)), &(pQueue->list));
} }
@ -71,7 +94,7 @@ int LQ_GetCount(LQUEUE * pQueue)
{ {
if (pQueue == NULL) { if (pQueue == NULL) {
fprintf(stderr, "Queue is NULL"); fprintf(stderr, "Error (%s): Pointer to LQUEUE is NULL.", __FUNCTION__ );
return -1; return -1;
} }

View File

@ -18,7 +18,8 @@ TRICK_EXEC_LINK_LIBS += -lpthread
# ================================================================================== # ==================================================================================
# All tests produced by this Makefile. Add new tests you create to this list. # All tests produced by this Makefile. Add new tests you create to this list.
# ================================================================================== # ==================================================================================
TESTS = dllist_unittest TESTS = dllist_unittest\
lqueue_unittest
# List of XML files produced by the tests. # List of XML files produced by the tests.
unittest_results = $(patsubst %,%.xml,$(TESTS)) unittest_results = $(patsubst %,%.xml,$(TESTS))
@ -58,3 +59,7 @@ $(unittest_objects): %.o: %.cpp
# ================================================================================== # ==================================================================================
$(TESTS) : %: %.o $(TESTS) : %: %.o
$(TRICK_CXX) $(TRICK_SYSTEM_LDFLAGS) -o $@ $^ -L${TRICK_HOME}/lib_${TRICK_HOST_CPU} $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS) $(TRICK_CXX) $(TRICK_SYSTEM_LDFLAGS) -o $@ $^ -L${TRICK_HOME}/lib_${TRICK_HOST_CPU} $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS)
# ----------------------------------------------------------------------------------
# The following unittest programs are also dependent on the indicated object files.
# ----------------------------------------------------------------------------------

View File

@ -0,0 +1,142 @@
#include <gtest/gtest.h>
#include <iostream>
#include "trick/lqueue.h"
/*
LQUEUE* LQ_Create(void);
int LQ_Delete(LQUEUE* lqueue); free an lqueue object created by LQ_Create.
void LQ_Init(LQUEUE*);
void LQ_EnQ(void* pData,LQUEUE* pQueue); insert data into queue
void* LQ_DeQ(LQUEUE* pQueue); extract data from queue
void* LQ_Peek(LQUEUE* pQueue); get data off queue without extracting
int LQ_GetCount(LQUEUE* pQueue); returns number of items in the queue
BUG: There's no way to free an LQUEUE without a memory leak.
*/
TEST(lqueue_test, LQUEUE_Create) {
LQUEUE* result = LQ_Create();
EXPECT_NE(result, nullptr);
EXPECT_EQ( LQ_GetCount(result), 0);
}
TEST(lqueue_test, LQUEUE_Delete) {
LQUEUE* lqueue = LQ_Create();
EXPECT_EQ( LQ_Delete(lqueue), 0);
}
TEST(lqueue_test, LQUEUE_Delete_null) {
LQUEUE* lqueue = nullptr;
std::cout << "NOTE: An error message is expected to follow." << std::endl;
EXPECT_EQ( LQ_Delete(lqueue), -1);
}
TEST(lqueue_test, LQUEUE_Init) {
LQUEUE* lqueue = LQ_Create();
lqueue->list.count = 1;
lqueue->list.head = (DLLNODE*)(0xDEADBEEF);
lqueue->list.tail = (DLLNODE*)(0xDEADBEEF);
LQ_Init(lqueue);
EXPECT_EQ(lqueue->list.count, 0);
EXPECT_EQ(lqueue->list.head, nullptr);
EXPECT_EQ(lqueue->list.tail, nullptr);
EXPECT_EQ(lqueue->list.compare, nullptr);
EXPECT_EQ( LQ_GetCount(lqueue), 0);
}
TEST(lqueue_test, LQUEUE_Init_null) {
LQUEUE* lqueue = nullptr;
std::cout << "NOTE: Two error messages are expected to follow." << std::endl;
LQ_Init(lqueue);
}
TEST(lqueue_test, LQUEUE_EnQ) {
int A,B,C;
A=1; B=2; C=3;
LQUEUE* lqueue = LQ_Create();
LQ_EnQ( &A, lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 1);
LQ_EnQ( &B, lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 2);
LQ_EnQ( &C, lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 3);
}
TEST(lqueue_test, LQUEUE_EnQ_null_queue) {
int A,B,C;
A=1; B=2; C=3;
LQUEUE* lqueue = LQ_Create();
std::cout << "NOTE: An error message is expected to follow." << std::endl;
LQ_EnQ( &A, nullptr);
}
TEST(lqueue_test, LQUEUE_DeQ) {
int A,B,C;
A=1; B=2; C=3;
LQUEUE* lqueue = LQ_Create();
LQ_EnQ( &A, lqueue);
LQ_EnQ( &B, lqueue);
LQ_EnQ( &C, lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 3);
LQ_DeQ( lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 2);
LQ_DeQ( lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 1);
LQ_DeQ( lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 0);
}
TEST(lqueue_test, LQUEUE_DeQ_null_queue) {
int A,B,C;
A=1; B=2; C=3;
LQUEUE* lqueue = nullptr;
std::cout << "NOTE: An error message is expected to follow." << std::endl;
LQ_EnQ( &A, lqueue);
}
TEST(lqueue_test, LQUEUE_Peek) {
int A,B,C;
A=1; B=2; C=3;
int* result;
LQUEUE* lqueue = LQ_Create();
LQ_EnQ( &A, lqueue);
LQ_EnQ( &B, lqueue);
LQ_EnQ( &C, lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 3);
result = (int*)LQ_Peek(lqueue);
EXPECT_EQ(*result, 1);
LQ_DeQ( lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 2);
result = (int*)LQ_Peek(lqueue);
EXPECT_EQ(*result, 2);
LQ_DeQ( lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 1);
result = (int*)LQ_Peek(lqueue);
EXPECT_EQ(*result, 3);
LQ_DeQ( lqueue);
EXPECT_EQ( LQ_GetCount(lqueue), 0);
std::cout << "NOTE: An error message is expected to follow." << std::endl;
result = (int*)LQ_Peek(lqueue);
EXPECT_EQ(result, nullptr);
}
TEST(lqueue_test, LQUEUE_Peek_null_queue) {
int A,B,C;
A=1; B=2; C=3;
int* result = (int*)(0xDEADBEEF);;
LQUEUE* lqueue = nullptr;
result = (int*)LQ_Peek(lqueue);
EXPECT_EQ(result, nullptr);
}