void testLSO(
    Test * pTest)
{
    uint8_t apdu[1000];
    int len;

    BACNET_LSO_DATA data;
    BACNET_LSO_DATA rxdata;

    memset(&rxdata, 0, sizeof(rxdata));


    characterstring_init_ansi(&data.requestingSrc, "foobar");
    data.operation = LIFE_SAFETY_OP_RESET;
    data.processId = 0x1234;
    data.targetObject.instance = 0x1000;
    data.targetObject.type = OBJECT_BINARY_INPUT;

    len = lso_encode_apdu(apdu, 100, &data);

    lso_decode_service_request(&apdu[4], len, &rxdata);

    ct_test(pTest, data.operation == rxdata.operation);
    ct_test(pTest, data.processId == rxdata.processId);
    ct_test(pTest, data.targetObject.instance == rxdata.targetObject.instance);
    ct_test(pTest, data.targetObject.type == rxdata.targetObject.type);
    ct_test(pTest, memcmp(data.requestingSrc.value, rxdata.requestingSrc.value,
            rxdata.requestingSrc.length) == 0);
}
示例#2
0
void test_ReinitializeDevice(
    Test * pTest)
{
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    uint8_t invoke_id = 128;
    uint8_t test_invoke_id = 0;
    BACNET_REINITIALIZED_STATE state;
    BACNET_REINITIALIZED_STATE test_state;
    BACNET_CHARACTER_STRING password;
    BACNET_CHARACTER_STRING test_password;

    state = BACNET_REINIT_WARMSTART;
    characterstring_init_ansi(&password, "John 3:16");
    len = rd_encode_apdu(&apdu[0], invoke_id, state, &password);
    ct_test(pTest, len != 0);
    apdu_len = len;

    len =
        rd_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_state,
        &test_password);
    ct_test(pTest, len != -1);
    ct_test(pTest, test_invoke_id == invoke_id);
    ct_test(pTest, test_state == state);
    ct_test(pTest, characterstring_same(&test_password, &password));

    return;
}
示例#3
0
文件: keylist.c 项目: empeeoh/BACnet
/* test access of a lot of entries */
static void testKeyListLarge(
    Test * pTest)
{
    int data1 = 42;
    int *data;
    OS_Keylist list;
    KEY key;
    int index;
    const unsigned num_keys = 1024 * 16;

    list = Keylist_Create();
    if (!list)
        return;

    for (key = 0; key < num_keys; key++) {
        index = Keylist_Data_Add(list, key, &data1);

    }
    for (key = 0; key < num_keys; key++) {
        data = Keylist_Data(list, key);
        ct_test(pTest, *data == data1);
    }
    for (index = 0; index < num_keys; index++) {
        data = Keylist_Data_Index(list, index);
        ct_test(pTest, *data == data1);
    }
    Keylist_Delete(list);

    return;
}
void testAtomicWriteFileAckAccess(
    Test * pTest,
    BACNET_ATOMIC_WRITE_FILE_DATA * data)
{
    BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 };
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    uint8_t invoke_id = 128;
    uint8_t test_invoke_id = 0;

    len = awf_encode_apdu(&apdu[0], invoke_id, data);
    ct_test(pTest, len != 0);
    apdu_len = len;

    len = awf_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data);
    ct_test(pTest, len != -1);
    ct_test(pTest, test_data.access == data->access);
    if (test_data.access == FILE_STREAM_ACCESS) {
        ct_test(pTest,
                test_data.type.stream.fileStartPosition ==
                data->type.stream.fileStartPosition);
    } else if (test_data.access == FILE_RECORD_ACCESS) {
        ct_test(pTest,
                test_data.type.record.fileStartRecord ==
                data->type.record.fileStartRecord);
    }
}
示例#5
0
文件: av.c 项目: TemcoEvan/T3-Modules
void testAnalog_Value(
    Test * pTest)
{
    uint8_t far apdu[MAX_APDU] = { 0 };
    int len = 0;
    uint32_t len_value = 0;
    uint8_t tag_number = 0;
    BACNET_OBJECT_TYPE decoded_type = OBJECT_ANALOG_VALUE;
    uint32_t decoded_instance = 0;
    uint32_t instance = 123;
    BACNET_ERROR_CLASS error_class;
    BACNET_ERROR_CODE error_code;

    len =
        Analog_Value_Encode_Property_APDU(&apdu[0], instance,
        PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
    ct_test(pTest, len != 0);
    len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
    ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
    len =
        decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
    ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE);
    ct_test(pTest, decoded_instance == instance);

    return;
}
示例#6
0
文件: bi.c 项目: Jongil-Park/Lin_PRJ
void testBinaryInput(
    Test * pTest)
{
    uint8_t apdu[MAX_APDU] = { 0 };
    int len = 0;
    uint32_t len_value = 0;
    uint8_t tag_number = 0;
    BACNET_OBJECT_TYPE decoded_type = OBJECT_BINARY_OUTPUT;
    uint32_t decoded_instance = 0;
    uint32_t instance = 123;
    BACNET_ERROR_CLASS error_class;
    BACNET_ERROR_CODE error_code;


    /* FIXME: we should do a lot more testing here... */
    len =
        Binary_Input_Encode_Property_APDU(&apdu[0], instance,
        PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
    ct_test(pTest, len >= 0);
    len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
    ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
    len =
        decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
    ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT);
    ct_test(pTest, decoded_instance == instance);

    return;
}
void testBinary_Value(
    Test * pTest)
{
    uint8_t apdu[MAX_APDU] = { 0 };
    int len = 0;
    uint32_t len_value = 0;
    uint8_t tag_number = 0;
    uint16_t decoded_type = 0;
    uint32_t decoded_instance = 0;
    BACNET_READ_PROPERTY_DATA rpdata;

    Binary_Value_Init();
    rpdata.application_data = &apdu[0];
    rpdata.application_data_len = sizeof(apdu);
    rpdata.object_type = OBJECT_BINARY_VALUE;
    rpdata.object_instance = 1;
    rpdata.object_property = PROP_OBJECT_IDENTIFIER;
    rpdata.array_index = BACNET_ARRAY_ALL;
    len = Binary_Value_Read_Property(&rpdata);
    ct_test(pTest, len != 0);
    len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
    ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
    len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
    ct_test(pTest, decoded_type == rpdata.object_type);
    ct_test(pTest, decoded_instance == rpdata.object_instance);

    return;
}
示例#8
0
void testBACnetDateTimeAdd(
    Test * pTest)
{
    BACNET_DATE_TIME bdatetime, test_bdatetime;
    uint32_t minutes = 0;
    int diff = 0;

    datetime_set_values(&bdatetime, 1900, 1, 1, 0, 0, 0, 0);
    datetime_copy(&test_bdatetime, &bdatetime);
    datetime_add_minutes(&bdatetime, minutes);
    diff = datetime_compare(&test_bdatetime, &bdatetime);
    ct_test(pTest, diff == 0);

    datetime_set_values(&bdatetime, 1900, 1, 1, 0, 0, 0, 0);
    datetime_add_minutes(&bdatetime, 60);
    datetime_set_values(&test_bdatetime, 1900, 1, 1, 1, 0, 0, 0);
    diff = datetime_compare(&test_bdatetime, &bdatetime);
    ct_test(pTest, diff == 0);

    datetime_set_values(&bdatetime, 1900, 1, 1, 0, 0, 0, 0);
    datetime_add_minutes(&bdatetime, (24 * 60));
    datetime_set_values(&test_bdatetime, 1900, 1, 2, 0, 0, 0, 0);
    diff = datetime_compare(&test_bdatetime, &bdatetime);
    ct_test(pTest, diff == 0);

    datetime_set_values(&bdatetime, 1900, 1, 1, 0, 0, 0, 0);
    datetime_add_minutes(&bdatetime, (31 * 24 * 60));
    datetime_set_values(&test_bdatetime, 1900, 2, 1, 0, 0, 0, 0);
    diff = datetime_compare(&test_bdatetime, &bdatetime);
    ct_test(pTest, diff == 0);
}
示例#9
0
void testAbortAPDU(
    Test * pTest,
    uint8_t invoke_id,
    uint8_t abort_reason,
    bool server)
{
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    uint8_t test_invoke_id = 0;
    uint8_t test_abort_reason = 0;
    bool test_server = false;

    len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
    apdu_len = len;
    ct_test(pTest, len != 0);
    len =
        abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
        &test_abort_reason, &test_server);
    ct_test(pTest, len != -1);
    ct_test(pTest, test_invoke_id == invoke_id);
    ct_test(pTest, test_abort_reason == abort_reason);
    ct_test(pTest, test_server == server);

    return;
}
示例#10
0
void testBACnetDayOfWeek(
    Test * pTest)
{
    uint8_t dow = 0;

    /* 1/1/1900 is a Monday */
    dow = day_of_week(1900, 1, 1);
    ct_test(pTest, dow == 1);

    /* 1/1/2007 is a Monday */
    dow = day_of_week(2007, 1, 1);
    ct_test(pTest, dow == 1);
    dow = day_of_week(2007, 1, 2);
    ct_test(pTest, dow == 2);
    dow = day_of_week(2007, 1, 3);
    ct_test(pTest, dow == 3);
    dow = day_of_week(2007, 1, 4);
    ct_test(pTest, dow == 4);
    dow = day_of_week(2007, 1, 5);
    ct_test(pTest, dow == 5);
    dow = day_of_week(2007, 1, 6);
    ct_test(pTest, dow == 6);
    dow = day_of_week(2007, 1, 7);
    ct_test(pTest, dow == 7);

    dow = day_of_week(2007, 1, 31);
    ct_test(pTest, dow == 3);
}
示例#11
0
void testDatetimeCodec(
    Test * pTest)
{
    uint8_t apdu[MAX_APDU];
    BACNET_DATE_TIME datetimeIn;
    BACNET_DATE_TIME datetimeOut;
    int inLen;
    int outLen;

    datetimeIn.date.day = 1;
    datetimeIn.date.month = 2;
    datetimeIn.date.wday = 3;
    datetimeIn.date.year = 1904;

    datetimeIn.time.hour = 5;
    datetimeIn.time.min = 6;
    datetimeIn.time.sec = 7;
    datetimeIn.time.hundredths = 8;

    inLen = bacapp_encode_context_datetime(apdu, 10, &datetimeIn);
    outLen = bacapp_decode_context_datetime(apdu, 10, &datetimeOut);

    ct_test(pTest, inLen == outLen);

    ct_test(pTest, datetimeIn.date.day == datetimeOut.date.day);
    ct_test(pTest, datetimeIn.date.month == datetimeOut.date.month);
    ct_test(pTest, datetimeIn.date.wday == datetimeOut.date.wday);
    ct_test(pTest, datetimeIn.date.year == datetimeOut.date.year);

    ct_test(pTest, datetimeIn.time.hour == datetimeOut.time.hour);
    ct_test(pTest, datetimeIn.time.min == datetimeOut.time.min);
    ct_test(pTest, datetimeIn.time.sec == datetimeOut.time.sec);
    ct_test(pTest, datetimeIn.time.hundredths == datetimeOut.time.hundredths);

}
示例#12
0
void testTimestampTimeDate(
    Test * pTest)
{
    BACNET_TIMESTAMP testTimestampIn;
    BACNET_TIMESTAMP testTimestampOut;
    uint8_t buffer[MAX_APDU];
    int inLen;
    int outLen;

    testTimestampIn.tag = TIME_STAMP_DATETIME;
    testTimestampIn.value.dateTime.time.hour = 1;
    testTimestampIn.value.dateTime.time.min = 2;
    testTimestampIn.value.dateTime.time.sec = 3;
    testTimestampIn.value.dateTime.time.hundredths = 4;

    testTimestampIn.value.dateTime.date.year = 1901;
    testTimestampIn.value.dateTime.date.month = 1;
    testTimestampIn.value.dateTime.date.wday = 2;
    testTimestampIn.value.dateTime.date.day = 3;

    memset(&testTimestampOut, 0, sizeof(testTimestampOut));

    inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn);
    outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut);

    ct_test(pTest, inLen == outLen);
    ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag);
    ct_test(pTest,
        testTimestampIn.value.dateTime.time.hour ==
        testTimestampOut.value.dateTime.time.hour);
    ct_test(pTest,
        testTimestampIn.value.dateTime.time.min ==
        testTimestampOut.value.dateTime.time.min);
    ct_test(pTest,
        testTimestampIn.value.dateTime.time.sec ==
        testTimestampOut.value.dateTime.time.sec);
    ct_test(pTest,
        testTimestampIn.value.dateTime.time.hundredths ==
        testTimestampOut.value.dateTime.time.hundredths);

    ct_test(pTest,
        testTimestampIn.value.dateTime.date.year ==
        testTimestampOut.value.dateTime.date.year);
    ct_test(pTest,
        testTimestampIn.value.dateTime.date.month ==
        testTimestampOut.value.dateTime.date.month);
    ct_test(pTest,
        testTimestampIn.value.dateTime.date.wday ==
        testTimestampOut.value.dateTime.date.wday);
    ct_test(pTest,
        testTimestampIn.value.dateTime.date.day ==
        testTimestampOut.value.dateTime.date.day);

}
示例#13
0
void test_Private_Transfer_Error(
    Test * pTest)
{
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    uint8_t invoke_id = 128;
    uint8_t test_invoke_id = 0;
    BACNET_ERROR_CLASS error_class = ERROR_CLASS_RESOURCES;
    BACNET_ERROR_CODE error_code = ERROR_CODE_OPERATIONAL_PROBLEM;
    BACNET_ERROR_CLASS test_error_class = 0;
    BACNET_ERROR_CODE test_error_code = 0;
    BACNET_PRIVATE_TRANSFER_DATA private_data;
    BACNET_PRIVATE_TRANSFER_DATA test_data;
    uint8_t test_value[480] = { 0 };
    int private_data_len = 0;
    uint8_t private_data_chunk[32] = { "I Love You, Patricia!" };
    BACNET_APPLICATION_DATA_VALUE data_value;
    BACNET_APPLICATION_DATA_VALUE test_data_value;

    private_data.vendorID = BACNET_VENDOR_ID;
    private_data.serviceNumber = 1;

    bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
        &private_data_chunk[0], &data_value);
    private_data_len =
        bacapp_encode_application_data(&test_value[0], &data_value);
    private_data.serviceParameters = &test_value[0];
    private_data.serviceParametersLen = private_data_len;

    len =
        ptransfer_error_encode_apdu(&apdu[0], invoke_id, error_class,
        error_code, &private_data);
    ct_test(pTest, len != 0);
    ct_test(pTest, len != -1);
    apdu_len = len;
    len =
        ptransfer_error_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
        &test_error_class, &test_error_code, &test_data);
    ct_test(pTest, len != -1);
    ct_test(pTest, test_invoke_id == invoke_id);
    ct_test(pTest, test_data.vendorID == private_data.vendorID);
    ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
    ct_test(pTest, test_error_class == error_class);
    ct_test(pTest, test_error_code == error_code);
    ct_test(pTest,
        test_data.serviceParametersLen == private_data.serviceParametersLen);
    len =
        bacapp_decode_application_data(test_data.serviceParameters,
        test_data.serviceParametersLen, &test_data_value);
    ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true);
}
示例#14
0
void testWhoHasData(
    Test * pTest,
    BACNET_WHO_HAS_DATA * data)
{
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    BACNET_WHO_HAS_DATA test_data;

    len = whohas_encode_apdu(&apdu[0], data);
    ct_test(pTest, len != 0);
    apdu_len = len;

    len = whohas_decode_apdu(&apdu[0], apdu_len, &test_data);
    ct_test(pTest, len != -1);
    ct_test(pTest, test_data.low_limit == data->low_limit);
    ct_test(pTest, test_data.high_limit == data->high_limit);
    ct_test(pTest, test_data.object_name == data->object_name);
    /* Object ID */
    if (data->object_name == false) {
        ct_test(pTest,
            test_data.object.identifier.type == data->object.identifier.type);
        ct_test(pTest,
            test_data.object.identifier.instance ==
            data->object.identifier.instance);
    }
    /* Object Name */
    else {
        ct_test(pTest, characterstring_same(&test_data.object.name,
                &data->object.name));
    }
}
示例#15
0
void testTimeSyncData(
    Test * pTest,
    BACNET_DATE * my_date,
    BACNET_TIME * my_time)
{
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    BACNET_DATE test_date;
    BACNET_TIME test_time;

    len = timesync_encode_apdu(&apdu[0], my_date, my_time);
    ct_test(pTest, len != 0);
    apdu_len = len;
    len = timesync_decode_apdu(&apdu[0], apdu_len, &test_date, &test_time);
    ct_test(pTest, len != -1);
    ct_test(pTest, datetime_compare_time(my_time, &test_time) == 0);
    ct_test(pTest, datetime_compare_date(my_date, &test_date) == 0);

    len = timesync_utc_encode_apdu(&apdu[0], my_date, my_time);
    ct_test(pTest, len != 0);
    apdu_len = len;
    len = timesync_utc_decode_apdu(&apdu[0], apdu_len, &test_date, &test_time);
    ct_test(pTest, len != -1);
    ct_test(pTest, datetime_compare_time(my_time, &test_time) == 0);
    ct_test(pTest, datetime_compare_date(my_date, &test_date) == 0);
}
示例#16
0
void testBACnetDateTimeWildcard(
    Test * pTest)
{
    BACNET_DATE_TIME bdatetime;
    bool status = false;

    datetime_set_values(&bdatetime, 1900, 1, 1, 0, 0, 0, 0);
    status = datetime_wildcard(&bdatetime);
    ct_test(pTest, status == false);

    datetime_wildcard_set(&bdatetime);
    status = datetime_wildcard(&bdatetime);
    ct_test(pTest, status == true);
}
示例#17
0
void testNPDU1(
    Test * pTest)
{
    uint8_t pdu[480] = { 0 };
    BACNET_ADDRESS dest = { 0 };
    BACNET_ADDRESS src = { 0 };
    BACNET_ADDRESS npdu_dest = { 0 };
    BACNET_ADDRESS npdu_src = { 0 };
    int len = 0;
    bool data_expecting_reply = false;
    BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
    BACNET_NPDU_DATA npdu_data = { 0 };
    int i = 0;  /* counter */
    int npdu_len = 0;
    bool network_layer_message = false; /* false if APDU */
    BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0;       /* optional */
    uint16_t vendor_id = 0;     /* optional, if net message type is > 0x80 */

    /* mac_len = 0 if global address */
    dest.mac_len = 0;
    for (i = 0; i < MAX_MAC_LEN; i++) {
        dest.mac[i] = 0;
    }
    /* DNET,DLEN,DADR */
    dest.net = 0;
    dest.len = 0;
    for (i = 0; i < MAX_MAC_LEN; i++) {
        dest.adr[i] = 0;
    }
    src.mac_len = 0;
    for (i = 0; i < MAX_MAC_LEN; i++) {
        src.mac[i] = 0;
    }
    /* SNET,SLEN,SADR */
    src.net = 0;
    src.len = 0;
    for (i = 0; i < MAX_MAC_LEN; i++) {
        src.adr[i] = 0;
    }
    npdu_encode_npdu_data(&npdu_data, false, priority);
    len = npdu_encode_pdu(&pdu[0], &dest, &src, &npdu_data);
    ct_test(pTest, len != 0);
    /* can we get the info back? */
    npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
    ct_test(pTest, npdu_len != 0);
    ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply);
    ct_test(pTest, npdu_data.network_layer_message == network_layer_message);
    if (npdu_data.network_layer_message) {
        ct_test(pTest, npdu_data.network_message_type == network_message_type);
    }
    ct_test(pTest, npdu_data.vendor_id == vendor_id);
    ct_test(pTest, npdu_data.priority == priority);
    ct_test(pTest, npdu_dest.mac_len == src.mac_len);
    ct_test(pTest, npdu_src.mac_len == dest.mac_len);
}
示例#18
0
int 
main(void)
{
	printf("key-value tests:\n");
	kv_test(unit_maxid(), (alloc_fn_t)unit_alloc, (free_fn_t)unit_free, (lkupp_fn_t)unit_lkupp,
		(add_fn_t)unit_add, (del_fn_t)unit_del, (lkup_fn_t)unit_lkup, (lkupa_fn_t)unit_lkupa,
		(lkupan_fn_t)unit_lkupan, (expandn_fn_t)unit_expandn, (expand_fn_t)unit_expand);
	kv_test(unit2_maxid(), (alloc_fn_t)unit2_alloc, (free_fn_t)unit2_free, (lkupp_fn_t)unit2_lkupp,
		(add_fn_t)unit2_add, (del_fn_t)unit2_del, (lkup_fn_t)unit2_lkup, (lkupa_fn_t)unit2_lkupa,
		(lkupan_fn_t)unit2_lkupan, (expandn_fn_t)unit2_expandn, (expand_fn_t)unit2_expand);
	kv_test(unit3_maxid(), (alloc_fn_t)unit3_alloc, (free_fn_t)unit3_free, (lkupp_fn_t)unit3_lkupp,
		(add_fn_t)unit3_add, (del_fn_t)unit3_del, (lkup_fn_t)unit3_lkup, (lkupa_fn_t)unit3_lkupa,
		(lkupan_fn_t)unit3_lkupan, (expandn_fn_t)unit3_expandn, (expand_fn_t)unit3_expand);
	assert(alloc_cnt == 0);
	printf("\tSUCCESS\n");
	
	printf("ert tests:\n");
	ert_test(unit4_maxid(), 3, (alloc_fn_t)unit4_alloc, (lkup_fn_t)unit4_lkup, (lkupa_fn_t)unit4_lkupa, 
		 (lkupan_fn_t)unit4_lkupan, (expandn_fn_t)unit4_expandn, (expand_fn_t)unit4_expand);
	ert_test(unit5_maxid(), 1, (alloc_fn_t)unit5_alloc, (lkup_fn_t)unit5_lkup, (lkupa_fn_t)unit5_lkupa, 
		 (lkupan_fn_t)unit5_lkupan, (expandn_fn_t)unit5_expandn, (expand_fn_t)unit5_expand);
	printf("\tSUCCESS\n");

	printf("captbl tests:\n");
	ct_test();
	printf("\tSUCCESS\n");

	printf("pgtbl tests:\n");
	pgt_test();
	printf("\tSUCCESS\n");
	
	return 0;
}
示例#19
0
void testDateEpoch(
    Test * pTest)
{
    uint32_t days = 0;
    uint16_t year = 0, test_year = 0;
    uint8_t month = 0, test_month = 0;
    uint8_t day = 0, test_day = 0;

    days = days_since_epoch(1900, 1, 1);
    ct_test(pTest, days == 0);
    days_since_epoch_into_ymd(days, &year, &month, &day);
    ct_test(pTest, year == 1900);
    ct_test(pTest, month == 1);
    ct_test(pTest, day == 1);


    for (year = 1900; year <= 2154; year++) {
        for (month = 1; month <= 12; month++) {
            for (day = 1; day <= month_days(year, month); day++) {
                days = days_since_epoch(year, month, day);
                days_since_epoch_into_ymd(days, &test_year, &test_month,
                    &test_day);
                ct_test(pTest, year == test_year);
                ct_test(pTest, month == test_month);
                ct_test(pTest, day == test_day);
            }
        }
    }
}
示例#20
0
void test_Private_Transfer_Ack(
    Test * pTest)
{
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    uint8_t invoke_id = 128;
    uint8_t test_invoke_id = 0;
    BACNET_PRIVATE_TRANSFER_DATA private_data;
    BACNET_PRIVATE_TRANSFER_DATA test_data;
    uint8_t test_value[480] = { 0 };
    int private_data_len = 0;
    char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" };
    BACNET_APPLICATION_DATA_VALUE data_value;
    BACNET_APPLICATION_DATA_VALUE test_data_value;
    bool status = false;

    private_data.vendorID = BACNET_VENDOR_ID;
    private_data.serviceNumber = 1;

    status =
        bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
        &private_data_chunk[0], &data_value);
    ct_test(pTest, status == true);
    private_data_len =
        bacapp_encode_application_data(&test_value[0], &data_value);

    private_data.serviceParameters = &test_value[0];
    private_data.serviceParametersLen = private_data_len;


    len = ptransfer_ack_encode_apdu(&apdu[0], invoke_id, &private_data);
    ct_test(pTest, len != 0);
    ct_test(pTest, len != -1);
    apdu_len = len;
    len =
        ptransfer_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
        &test_data);
    ct_test(pTest, len != -1);
    ct_test(pTest, test_invoke_id == invoke_id);
    ct_test(pTest, test_data.vendorID == private_data.vendorID);
    ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
    ct_test(pTest,
        test_data.serviceParametersLen == private_data.serviceParametersLen);
    len =
        bacapp_decode_application_data(test_data.serviceParameters,
        test_data.serviceParametersLen, &test_data_value);
    ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true);
}
示例#21
0
void test_memcopy(
    Test * pTest)
{
    char *data1 = "Joshua";
    char *data2 = "Anna";
    char buffer[480] = "";
    char big_buffer[480] = "";
    size_t len = 0;

    len = memcopy(&buffer[0], &data1[0], 0, sizeof(data1), sizeof(buffer));
    ct_test(pTest, len == sizeof(data1));
    ct_test(pTest, memcmp(&buffer[0], &data1[0], len) == 0);
    len = memcopy(&buffer[0], &data2[0], len, sizeof(data2), sizeof(buffer));
    ct_test(pTest, len == sizeof(data2));
    len =
        memcopy(&buffer[0], &big_buffer[0], 1, sizeof(big_buffer),
        sizeof(buffer));
    ct_test(pTest, len == 0);
}
示例#22
0
static void testDevIdRef(
    Test * pTest)
{
    BACNET_DEVICE_OBJECT_REFERENCE inData;
    BACNET_DEVICE_OBJECT_REFERENCE outData;
    uint8_t buffer[MAX_APDU];
    int inLen;
    int outLen;

    inData.deviceIndentifier.instance = 0x4343;
    inData.deviceIndentifier.type = OBJECT_DEVICE;
    inLen = bacapp_encode_device_obj_ref(buffer, &inData);
    outLen = bacapp_decode_device_obj_ref(buffer, &outData);
    ct_test(pTest, outLen == inLen);
    ct_test(pTest,
        inData.deviceIndentifier.instance ==
        outData.deviceIndentifier.instance);
    ct_test(pTest,
        inData.deviceIndentifier.type == outData.deviceIndentifier.type);
}
示例#23
0
void testAbort(
    Test * pTest)
{
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    uint8_t invoke_id = 0;
    uint8_t test_invoke_id = 0;
    uint8_t abort_reason = 0;
    uint8_t test_abort_reason = 0;
    bool server = false;
    bool test_server = false;

    len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
    ct_test(pTest, len != 0);
    apdu_len = len;
    len =
        abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
        &test_abort_reason, &test_server);
    ct_test(pTest, len != -1);
    ct_test(pTest, test_invoke_id == invoke_id);
    ct_test(pTest, test_abort_reason == abort_reason);
    ct_test(pTest, test_server == server);

    /* change type to get negative response */
    apdu[0] = PDU_TYPE_REJECT;
    len =
        abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
        &test_abort_reason, &test_server);
    ct_test(pTest, len == -1);

    /* test NULL APDU */
    len =
        abort_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_abort_reason,
        &test_server);
    ct_test(pTest, len == -1);

    /* force a zero length */
    len =
        abort_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_abort_reason,
        &test_server);
    ct_test(pTest, len == 0);

    /* check them all...   */
    for (invoke_id = 0; invoke_id < 255; invoke_id++) {
        for (abort_reason = 0; abort_reason < 255; abort_reason++) {
            testAbortAPDU(pTest, invoke_id, abort_reason, false);
            testAbortAPDU(pTest, invoke_id, abort_reason, true);
        }
    }
}
/* test the ring buffer */
static void testRingAroundBuffer(
    Test * pTest,
    RING_BUFFER * test_buffer,
    uint8_t * data_element,
    unsigned element_size,
    unsigned element_count)
{
    volatile uint8_t *test_data;
    unsigned index;
    unsigned data_index;
    unsigned count;
    unsigned dummy;
    bool status;

    ct_test(pTest, Ringbuf_Empty(test_buffer));
    /* test the ring around the buffer */
    for (index = 0; index < element_count; index++) {
        for (count = 1; count < 4; count++) {
            dummy = index * count;
            for (data_index = 0; data_index < element_size; data_index++) {
                data_element[data_index] = dummy;
            }
            status = Ringbuf_Put(test_buffer, data_element);
            ct_test(pTest, status == true);
        }

        for (count = 1; count < 4; count++) {
            dummy = index * count;
            test_data = Ringbuf_Peek(test_buffer);
            ct_test(pTest, test_data);
            if (test_data) {
                for (data_index = 0; data_index < element_size; data_index++) {
                    ct_test(pTest, test_data[data_index] == dummy);
                }
            }
            (void) Ringbuf_Pop(test_buffer, NULL);
        }
    }
    ct_test(pTest, Ringbuf_Empty(test_buffer));
}
示例#25
0
void testReadProperty(
    Test * pTest)
{
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    uint8_t invoke_id = 128;
    uint8_t test_invoke_id = 0;
    BACNET_READ_PROPERTY_DATA rpdata;
    BACNET_READ_PROPERTY_DATA test_data;

    rpdata.object_type = OBJECT_DEVICE;
    rpdata.object_instance = 1;
    rpdata.object_property = PROP_OBJECT_IDENTIFIER;
    rpdata.array_index = BACNET_ARRAY_ALL;
    len = rp_encode_apdu(&apdu[0], invoke_id, &rpdata);
    ct_test(pTest, len != 0);
    apdu_len = len;

    len = rp_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data);
    ct_test(pTest, len != -1);
    ct_test(pTest, test_data.object_type == rpdata.object_type);
    ct_test(pTest, test_data.object_instance == rpdata.object_instance);
    ct_test(pTest, test_data.object_property == rpdata.object_property);
    ct_test(pTest, test_data.array_index == rpdata.array_index);

    return;
}
示例#26
0
static void testWildcardDateTime(
    Test * pTest)
{
    BACNET_DATE_TIME bdatetime1, bdatetime2;
    BACNET_DATE bdate;
    BACNET_TIME btime;
    int diff = 0;

    datetime_wildcard_set(&bdatetime1);
    ct_test(pTest, datetime_wildcard(&bdatetime1));
    ct_test(pTest, datetime_wildcard_present(&bdatetime1));
    datetime_copy(&bdatetime2, &bdatetime1);
    diff = datetime_wildcard_compare(&bdatetime1, &bdatetime2);
    ct_test(pTest, diff == 0);
    datetime_time_wildcard_set(&btime);
    datetime_date_wildcard_set(&bdate);
    datetime_set(&bdatetime1, &bdate, &btime);
    diff = datetime_wildcard_compare(&bdatetime1, &bdatetime2);
    ct_test(pTest, diff == 0);

    return;
}
void testAtomicWriteFileAccess(
    Test * pTest,
    BACNET_ATOMIC_WRITE_FILE_DATA * data)
{
    BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 };
    uint8_t apdu[480] = { 0 };
    int len = 0;
    int apdu_len = 0;
    uint8_t invoke_id = 128;
    uint8_t test_invoke_id = 0;

    len = awf_encode_apdu(&apdu[0], invoke_id, data);
    ct_test(pTest, len != 0);
    apdu_len = len;

    len = awf_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data);
    ct_test(pTest, len != -1);
    ct_test(pTest, test_data.object_type == data->object_type);
    ct_test(pTest, test_data.object_instance == data->object_instance);
    ct_test(pTest, test_data.access == data->access);
    if (test_data.access == FILE_STREAM_ACCESS) {
        ct_test(pTest,
                test_data.type.stream.fileStartPosition ==
                data->type.stream.fileStartPosition);
    } else if (test_data.access == FILE_RECORD_ACCESS) {
        ct_test(pTest,
                test_data.type.record.fileStartRecord ==
                data->type.record.fileStartRecord);
        ct_test(pTest,
                test_data.type.record.returnedRecordCount ==
                data->type.record.returnedRecordCount);
    }
    ct_test(pTest,
            octetstring_length(&test_data.fileData) ==
            octetstring_length(&data->fileData));
    ct_test(pTest, memcmp(octetstring_value(&test_data.fileData),
                          octetstring_value(&data->fileData),
                          octetstring_length(&test_data.fileData)) == 0);
}
示例#28
0
static void testDevObjPropRef(
    Test * pTest,
    BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *inData)
{
    BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE outData;
    uint8_t buffer[MAX_APDU] = {0};
    int inLen = 0;
    int outLen = 0;

    /* encode */
    inLen = bacapp_encode_device_obj_property_ref(buffer, inData);
    /* add a closing tag at the end of the buffer to verify proper handling
       when that is encountered in real packets */
    encode_closing_tag(&buffer[inLen], 3);
    /* decode */
    outLen = bacapp_decode_device_obj_property_ref(buffer, &outData);
    ct_test(pTest, outLen == inLen);
    ct_test(pTest,
        inData->objectIdentifier.instance == outData.objectIdentifier.instance);
    ct_test(pTest,
        inData->objectIdentifier.type == outData.objectIdentifier.type);
    ct_test(pTest, inData->propertyIdentifier == outData.propertyIdentifier);
    if (inData->arrayIndex != BACNET_ARRAY_ALL) {
        ct_test(pTest, inData->arrayIndex == outData.arrayIndex);
    } else {
        ct_test(pTest, outData.arrayIndex == BACNET_ARRAY_ALL);
    }
    if (inData->deviceIndentifier.type == OBJECT_DEVICE) {
        ct_test(pTest,
            inData->deviceIndentifier.instance ==
            outData.deviceIndentifier.instance);
        ct_test(pTest,
            inData->deviceIndentifier.type == outData.deviceIndentifier.type);
    } else {
        ct_test(pTest,outData.deviceIndentifier.instance == BACNET_NO_DEV_ID);
        ct_test(pTest,outData.deviceIndentifier.type == BACNET_NO_DEV_TYPE);
    }
}
void testFilename(
    Test * pTest)
{
    char *data1 = "c:\\Joshua\\run";
    char *data2 = "/home/Anna/run";
    char *data3 = "c:\\Program Files\\Christopher\\run.exe";
    char *data4 = "//Mary/data/run";
    char *data5 = "bin\\run";
    char *filename = NULL;

    filename = filename_remove_path(data1);
    ct_test(pTest, strcmp("run", filename) == 0);
    filename = filename_remove_path(data2);
    ct_test(pTest, strcmp("run", filename) == 0);
    filename = filename_remove_path(data3);
    ct_test(pTest, strcmp("run.exe", filename) == 0);
    filename = filename_remove_path(data4);
    ct_test(pTest, strcmp("run", filename) == 0);
    filename = filename_remove_path(data5);
    ct_test(pTest, strcmp("run", filename) == 0);

    return;
}
示例#30
0
void testTimestampSequence(
    Test * pTest)
{
    BACNET_TIMESTAMP testTimestampIn;
    BACNET_TIMESTAMP testTimestampOut;
    uint8_t buffer[MAX_APDU];
    int inLen;
    int outLen;

    testTimestampIn.tag = TIME_STAMP_SEQUENCE;
    testTimestampIn.value.sequenceNum = 0x1234;

    memset(&testTimestampOut, 0, sizeof(testTimestampOut));


    inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn);
    outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut);

    ct_test(pTest, inLen == outLen);
    ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag);
    ct_test(pTest,
        testTimestampIn.value.sequenceNum ==
        testTimestampOut.value.sequenceNum);
}