📄 sahpi_struct_utils_test.c
字号:
if (err != expected_err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d; Expected error=%d\n", err, expected_err); return -1; } err = oh_fprint_bigtext(0, &big_buffer); if (err != expected_err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d; Expected error=%d\n", err, expected_err); return -1; }#endif /* Normal write to file testcase */ { FILE *fp, *big_fp; const char *name = "tmp"; const char *big_name = "tmpbig"; const char *mode = "a"; fp = fopen(name, mode); if (fp == NULL) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); return -1; } err = oh_fprint_text(fp, &buffer); if (err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d\n", err); return -1; } big_fp = fopen(big_name, mode); if (big_fp == NULL) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); return -1; } err = oh_fprint_bigtext(big_fp, &big_buffer); if (err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d\n", err); return -1; } fclose(fp); fclose(big_fp); unlink(name); unlink(big_name); } } /****************************** * oh_print_sensorrec testcases ******************************/ { SaHpiSensorRecT sensor, default_sensor; sensor.Num = 1; sensor.Type = SAHPI_VOLTAGE; sensor.Category = SAHPI_EC_THRESHOLD; sensor.Events = SAHPI_ES_LOWER_MAJOR | SAHPI_ES_LOWER_MINOR; sensor.EventCtrl = SAHPI_SEC_READ_ONLY; sensor.DataFormat.IsSupported = SAHPI_TRUE; sensor.DataFormat.ReadingType = SAHPI_SENSOR_READING_TYPE_INT64; sensor.DataFormat.BaseUnits = SAHPI_SU_VOLTS; sensor.DataFormat.ModifierUnits = SAHPI_SU_SECOND; sensor.DataFormat.ModifierUse = SAHPI_SMUU_BASIC_TIMES_MODIFIER; sensor.DataFormat.Percentage = SAHPI_FALSE; sensor.DataFormat.Range.Flags = SAHPI_SRF_MIN | SAHPI_SRF_MAX | SAHPI_SRF_NOMINAL | SAHPI_SRF_NORMAL_MIN | SAHPI_SRF_NORMAL_MAX; sensor.DataFormat.Range.Min.IsSupported = SAHPI_TRUE; sensor.DataFormat.Range.Min.Type = SAHPI_SENSOR_READING_TYPE_INT64; sensor.DataFormat.Range.Min.Value.SensorInt64 = 0; sensor.DataFormat.Range.Max.IsSupported = SAHPI_TRUE; sensor.DataFormat.Range.Max.Type = SAHPI_SENSOR_READING_TYPE_INT64; sensor.DataFormat.Range.Max.Value.SensorInt64 = 100; sensor.DataFormat.Range.Nominal.IsSupported = SAHPI_TRUE; sensor.DataFormat.Range.Nominal.Type = SAHPI_SENSOR_READING_TYPE_INT64; sensor.DataFormat.Range.Nominal.Value.SensorInt64 = 50; sensor.DataFormat.Range.NormalMax.IsSupported = SAHPI_TRUE; sensor.DataFormat.Range.NormalMax.Type = SAHPI_SENSOR_READING_TYPE_INT64; sensor.DataFormat.Range.NormalMax.Value.SensorInt64 = 75; sensor.DataFormat.Range.NormalMin.IsSupported = SAHPI_TRUE; sensor.DataFormat.Range.NormalMin.Type = SAHPI_SENSOR_READING_TYPE_INT64; sensor.DataFormat.Range.NormalMin.Value.SensorInt64 = 25; sensor.DataFormat.AccuracyFactor = 0.05; sensor.Oem = 0xFF; sensor.ThresholdDefn.IsAccessible = SAHPI_TRUE; sensor.ThresholdDefn.ReadThold = SAHPI_STM_LOW_MINOR | SAHPI_STM_LOW_MAJOR | SAHPI_STM_LOW_CRIT | SAHPI_STM_LOW_HYSTERESIS; sensor.ThresholdDefn.WriteThold = SAHPI_STM_UP_MINOR | SAHPI_STM_UP_MAJOR | SAHPI_STM_UP_CRIT | SAHPI_STM_UP_HYSTERESIS; sensor.ThresholdDefn.Nonlinear = SAHPI_TRUE; /* oh_print_sensorrec: Bad parameter testcase */ expected_err = SA_ERR_HPI_INVALID_PARAMS; err = oh_print_sensorrec(0, 0); if (err != expected_err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d; Expected error=%d\n", err, expected_err); return -1; } /* oh_print_sensorrec: Default sensor testcase */ memset(&default_sensor, 0, sizeof(SaHpiSensorRecT)); err = oh_print_sensorrec(&default_sensor, 0); if (err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d\n", err); return -1; } /* oh_print_sensorrec: Normal sensor testcase */ err = oh_print_sensorrec(&sensor, 0); if (err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d\n", err); return -1; } } /******************************* * oh_print_textbuffer testcases *******************************/ { SaHpiTextBufferT textbuffer, default_textbuffer; textbuffer.DataType = SAHPI_TL_TYPE_TEXT; textbuffer.Language = SAHPI_LANG_ZULU; strcpy(textbuffer.Data, "Test Data"); textbuffer.DataLength = strlen(textbuffer.Data); /* oh_print_textbuffer: Bad parameter testcase */ expected_err = SA_ERR_HPI_INVALID_PARAMS; err = oh_print_textbuffer(0, 0); if (err != expected_err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d; Expected error=%d\n", err, expected_err); return -1; } /* oh_print_textbuffer: Default textbuffer testcase */ printf("Default TextBuffer\n"); err = oh_print_textbuffer(&default_textbuffer, 1); if (err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d\n", err); return -1; } /* oh_print_textbuffer: Normal textbuffer testcase */ printf("Normal TextBuffer\n"); err = oh_print_textbuffer(&textbuffer, 1); if (err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d\n", err); return -1; } } /************************** * oh_print_event testcases **************************/ { SaHpiEventT sensor_event, default_event; sensor_event.Source = 1; sensor_event.EventType = SAHPI_ET_SENSOR; sensor_event.Severity = SAHPI_CRITICAL; sensor_event.EventDataUnion.SensorEvent.SensorNum = 2; sensor_event.EventDataUnion.SensorEvent.SensorType = SAHPI_VOLTAGE; sensor_event.EventDataUnion.SensorEvent.EventCategory = SAHPI_EC_THRESHOLD; sensor_event.EventDataUnion.SensorEvent.Assertion = SAHPI_TRUE; sensor_event.EventDataUnion.SensorEvent.EventState = SAHPI_ES_LOWER_MINOR; sensor_event.EventDataUnion.SensorEvent.OptionalDataPresent = sensor_event.EventDataUnion.SensorEvent.OptionalDataPresent | SAHPI_SOD_TRIGGER_READING | SAHPI_SOD_TRIGGER_THRESHOLD | SAHPI_SOD_PREVIOUS_STATE | SAHPI_SOD_CURRENT_STATE | SAHPI_SOD_OEM | SAHPI_SOD_SENSOR_SPECIFIC; sensor_event.EventDataUnion.SensorEvent.TriggerReading.IsSupported = SAHPI_TRUE; sensor_event.EventDataUnion.SensorEvent.TriggerReading.Type = SAHPI_SENSOR_READING_TYPE_INT64; sensor_event.EventDataUnion.SensorEvent.TriggerReading.Value.SensorInt64 = 100; sensor_event.EventDataUnion.SensorEvent.TriggerThreshold.IsSupported = SAHPI_TRUE; sensor_event.EventDataUnion.SensorEvent.TriggerThreshold.Type = SAHPI_SENSOR_READING_TYPE_INT64; sensor_event.EventDataUnion.SensorEvent.TriggerThreshold.Value.SensorInt64 = 101; sensor_event.EventDataUnion.SensorEvent.PreviousState = SAHPI_ES_LOWER_MINOR | SAHPI_ES_LOWER_MAJOR; sensor_event.EventDataUnion.SensorEvent.CurrentState = SAHPI_ES_LOWER_MINOR; sensor_event.EventDataUnion.SensorEvent.Oem = 32; sensor_event.EventDataUnion.SensorEvent.SensorSpecific = 33; /* oh_print_event: Bad parameter testcase */ expected_err = SA_ERR_HPI_INVALID_PARAMS; err = oh_print_event(0, 0); if (err != expected_err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d; Expected error=%d\n", err, expected_err); return -1; } /* oh_print_event: Default event testcase */ printf("Default Event\n"); err = oh_print_event(&default_event, 1); if (err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d\n", err); return -1; } /* oh_print_event: Normal sensor event testcase */ printf("Normal Sensor Event\n"); err = oh_print_event(&sensor_event, 1); if (err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d\n", err); return -1; } /* oh_print_event: Normal sensor event - no optional sensor data testcase */ printf("Normal Sensor Event - no optional sensor data\n"); sensor_event.EventDataUnion.SensorEvent.OptionalDataPresent = 0; err = oh_print_event(&sensor_event, 1); if (err) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); printf(" Received error=%d\n", err); return -1; } } /******************************* * oh_valid_textbuffer testcases *******************************/ { SaHpiTextBufferT buffer; SaHpiBoolT result, expected_result; /* oh_valid_textbuffer: NULL buffer testcase */ expected_result = SAHPI_FALSE; result = oh_valid_textbuffer(0); if (result != expected_result) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); return -1; } /* oh_valid_textbuffer: Bad text type testcase */ expected_result = SAHPI_FALSE; oh_init_textbuffer(&buffer); buffer.DataType = BAD_TYPE; result = oh_valid_textbuffer(&buffer); if (result != expected_result) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); return -1; } /* oh_valid_textbuffer: Bad language type testcase */ expected_result = SAHPI_FALSE; oh_init_textbuffer(&buffer); buffer.Language = BAD_TYPE; result = oh_valid_textbuffer(&buffer); if (result != expected_result) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); return -1; } /* oh_valid_textbuffer: Bad Unicode length testcase */ expected_result = SAHPI_FALSE; oh_init_textbuffer(&buffer); buffer.DataType = SAHPI_TL_TYPE_UNICODE; strcpy(buffer.Data, "123"); buffer.DataLength = strlen("123"); result = oh_valid_textbuffer(&buffer); if (result != expected_result) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); return -1; } /* oh_valid_textbuffer: Bad Data text cases */ expected_result = SAHPI_FALSE; oh_init_textbuffer(&buffer); buffer.DataType = SAHPI_TL_TYPE_BCDPLUS; strcpy(buffer.Data, "123"); buffer.Data[1] = ';'; buffer.DataLength = strlen("123"); result = oh_valid_textbuffer(&buffer); if (result != expected_result) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); return -1; } buffer.DataType = SAHPI_TL_TYPE_ASCII6; buffer.Data[1] = 0xff; result = oh_valid_textbuffer(&buffer); if (result != expected_result) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); return -1; } /* oh_valid_textbuffer: Good buffer testcase */ expected_result = SAHPI_TRUE; oh_init_textbuffer(&buffer); result = oh_valid_textbuffer(&buffer); if (result != expected_result) { printf(" Error! Testcase failed. Line=%d\n", __LINE__); return -1; } } /****************************** * oh_valid_thresholds testcases ******************************/ { SaHpiSensorThresholdsT default_thresholds_int64, test_thresholds_int64; SaHpiSensorThresholdsT default_thresholds_float64, test_thresholds_float64; SaHpiSensorThresholdsT default_thresholds_uint64, test_thresholds_uint64; SaHpiSensorDataFormatT default_format_int64, test_format_int64; SaHpiSensorDataFormatT default_format_float64, test_format_float64; SaHpiSensorDataFormatT default_format_uint64, test_format_uint64; SaHpiSensorThdMaskT default_writable_thresholds, test_writable_thresholds; default_thresholds_int64.UpCritical.IsSupported = SAHPI_TRUE; default_thresholds_int64.UpCritical.Type = SAHPI_SENSOR_READING_TYPE_INT64; default_thresholds_int64.UpCritical.Value.SensorInt64 = 50; default_thresholds_int64.UpMajor.IsSupported = SAHPI_TRUE; default_thresholds_int64.UpMajor.Type = SAHPI_SENSOR_READING_TYPE_INT64; default_thresholds_int64.UpMajor.Value.SensorInt64 = 40; default_thresholds_int64.UpMinor.IsSupported = SAHPI_TRUE; default_thresholds_int64.UpMinor.Type = SAHPI_SENSOR_READING_TYPE_INT64; default_thresholds_int64.UpMinor.Value.SensorInt64 = 30; default_thresholds_int64.LowMinor.IsSupported = SAHPI_TRUE; default_thresholds_int64.LowMinor.Type = SAHPI_SENSOR_READING_TYPE_INT64; default_thresholds_int64.LowMinor.Value.SensorInt64 = 20; default_thresholds_int64.LowMajor.IsSupported = SAHPI_TRUE; default_thresholds_int64.LowMajor.Type = SAHPI_SENSOR_READING_TYPE_INT64; default_thresholds_int64.LowMajor.Value.SensorInt64 = 10; default_thresholds_int64.LowCritical.IsSupported = SAHPI_TRUE; default_thresholds_int64.LowCritical.Type = SAHPI_SENSOR_READING_TYPE_INT64; default_thresholds_int64.LowCritical.Value.SensorInt64 = 0; default_thresholds_int64.PosThdHysteresis.IsSupported = SAHPI_TRUE; default_thresholds_int64.PosThdHysteresis.Type = SAHPI_SENSOR_READING_TYPE_INT64; default_thresholds_int64.PosThdHysteresis.Value.SensorInt64 = 2; default_thresholds_int64.NegThdHysteresis.IsSupported = SAHPI_TRUE; default_thresholds_int64.NegThdHysteresis.Type = SAHPI_SENSOR_READING_TYPE_INT64; default_thresholds_int64.NegThdHysteresis.Value.SensorInt64 = 2; default_format_int64.IsSupported = SAHPI_TRUE; default_format_int64.ReadingType = SAHPI_SENSOR_READING_TYPE_INT64; default_format_int64.Range.Flags = SAHPI_SRF_MAX | SAHPI_SRF_MIN; default_format_int64.Range.Max.Value.SensorInt64 = 60; default_format_int64.Range.Min.Value.SensorInt64 = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -