From 625ff40d7118e39a346ead7575fc9c0d9f6f374b Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 18 Oct 2007 11:50:14 +0000 Subject: [PATCH] Moved bacstr.c back to src. Since gcc and others tool linkers can remove unused functions, this turned out to be a wasted effort. --- bacnet-stack/lib/Makefile | 4 +- bacnet-stack/lib/makefile.b32 | 4 +- bacnet-stack/ports/at91sam7s/makefile | 4 +- bacnet-stack/ports/atmega168/Makefile | 4 +- bacnet-stack/src/bacdcode/bitstring.c | 156 ------------------ bacnet-stack/src/bacdcode/bitstring_test.c | 70 -------- .../src/bacdcode/characterstring_test.c | 100 ----------- bacnet-stack/src/bacdcode/main.c | 99 ----------- bacnet-stack/src/bacdcode/octetstring.c | 150 ----------------- bacnet-stack/src/bacdcode/octetstring_test.c | 103 ------------ bacnet-stack/src/{bacdcode => }/bacstr.c | 0 .../{src/bacdcode => test}/bacstr.mak | 0 12 files changed, 4 insertions(+), 690 deletions(-) delete mode 100644 bacnet-stack/src/bacdcode/bitstring.c delete mode 100644 bacnet-stack/src/bacdcode/bitstring_test.c delete mode 100644 bacnet-stack/src/bacdcode/characterstring_test.c delete mode 100644 bacnet-stack/src/bacdcode/main.c delete mode 100644 bacnet-stack/src/bacdcode/octetstring.c delete mode 100644 bacnet-stack/src/bacdcode/octetstring_test.c rename bacnet-stack/src/{bacdcode => }/bacstr.c (100%) rename bacnet-stack/{src/bacdcode => test}/bacstr.mak (100%) diff --git a/bacnet-stack/lib/Makefile b/bacnet-stack/lib/Makefile index d0b02521..8652b222 100644 --- a/bacnet-stack/lib/Makefile +++ b/bacnet-stack/lib/Makefile @@ -30,9 +30,7 @@ CORE_SRC = \ $(BACNET_CORE)/bacdcode/bacdcode.c \ $(BACNET_CORE)/bacdcode/bacint.c \ $(BACNET_CORE)/bacdcode/bacreal.c \ - $(BACNET_CORE)/bacdcode/bitstring.c \ - $(BACNET_CORE)/bacdcode/octetstring.c \ - $(BACNET_CORE)/bacdcode/characterstring.c \ + $(BACNET_CORE)/bacstr.c \ $(BACNET_CORE)/bacapp.c \ $(BACNET_CORE)/bacprop.c \ $(BACNET_CORE)/bactext.c \ diff --git a/bacnet-stack/lib/makefile.b32 b/bacnet-stack/lib/makefile.b32 index 53a61a49..23ccd42e 100644 --- a/bacnet-stack/lib/makefile.b32 +++ b/bacnet-stack/lib/makefile.b32 @@ -40,9 +40,7 @@ CORE1_SRC = $(BACNET_CORE)\apdu.c \ $(BACNET_CORE)\bacdcode\bacdcode.c \ $(BACNET_CORE)\bacdcode\bacint.c \ $(BACNET_CORE)\bacdcode\bacreal.c \ - $(BACNET_CORE)\bacdcode\bitstring.c \ - $(BACNET_CORE)\bacdcode\octetstring.c \ - $(BACNET_CORE)\bacdcode\characterstring.c \ + $(BACNET_CORE)\bacstr.c \ $(BACNET_CORE)\bacapp.c \ $(BACNET_CORE)\bacprop.c \ $(BACNET_CORE)\bactext.c \ diff --git a/bacnet-stack/ports/at91sam7s/makefile b/bacnet-stack/ports/at91sam7s/makefile index e630a492..16930f68 100644 --- a/bacnet-stack/ports/at91sam7s/makefile +++ b/bacnet-stack/ports/at91sam7s/makefile @@ -68,9 +68,7 @@ CORESRC = $(BACNET_CORE)/npdu.c \ $(BACNET_CORE)/bacdcode/bacdcode.c \ $(BACNET_CORE)/bacdcode/bacint.c \ $(BACNET_CORE)/bacdcode/bacreal.c \ - $(BACNET_CORE)/bacdcode/bitstring.c \ - $(BACNET_CORE)/bacdcode/octetstring.c \ - $(BACNET_CORE)/bacdcode/characterstring.c \ + $(BACNET_CORE)/bacstr.c \ $(BACNET_CORE)/bacaddr.c \ $(BACNET_CORE)/abort.c \ $(BACNET_CORE)/bacerror.c \ diff --git a/bacnet-stack/ports/atmega168/Makefile b/bacnet-stack/ports/atmega168/Makefile index 384e86db..26a8c549 100644 --- a/bacnet-stack/ports/atmega168/Makefile +++ b/bacnet-stack/ports/atmega168/Makefile @@ -39,9 +39,7 @@ CORESRC = \ $(BACNET_CORE)/bacdcode/bacdcode.c \ $(BACNET_CORE)/bacdcode/bacint.c \ $(BACNET_CORE)/bacdcode/bacreal.c \ - $(BACNET_CORE)/bacdcode/bitstring.c \ - $(BACNET_CORE)/bacdcode/octetstring.c \ - $(BACNET_CORE)/bacdcode/characterstring.c \ + $(BACNET_CORE)/bacstr.c \ $(BACNET_CORE)/iam.c \ $(BACNET_CORE)/rp.c \ $(BACNET_CORE)/whois.c \ diff --git a/bacnet-stack/src/bacdcode/bitstring.c b/bacnet-stack/src/bacdcode/bitstring.c deleted file mode 100644 index d4386ba2..00000000 --- a/bacnet-stack/src/bacdcode/bitstring.c +++ /dev/null @@ -1,156 +0,0 @@ -/*####COPYRIGHTBEGIN#### - ------------------------------------------- - Copyright (C) 2004 Steve Karg - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to: - The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA. - - As a special exception, if other files instantiate templates or - use macros or inline functions from this file, or you compile - this file and link it with other works to produce a work based - on this file, this file does not by itself cause the resulting - work to be covered by the GNU General Public License. However - the source code for this file must still be made available in - accordance with section (3) of the GNU General Public License. - - This exception does not invalidate any other reasons why a work - based on this file might be covered by the GNU General Public - License. - ------------------------------------------- -####COPYRIGHTEND####*/ - -#include -#include -#include /* for strlen */ -#include "bacstr.h" -#include "bits.h" - -void bitstring_init(BACNET_BIT_STRING * bit_string) -{ - int i; - - bit_string->bits_used = 0; - for (i = 0; i < MAX_BITSTRING_BYTES; i++) { - bit_string->value[i] = 0; - } -} - -void bitstring_set_bit(BACNET_BIT_STRING * bit_string, uint8_t bit, - bool value) -{ - uint8_t byte_number = bit / 8; - uint8_t bit_mask = 1; - - if (byte_number < MAX_BITSTRING_BYTES) { - /* set max bits used */ - if (bit_string->bits_used < (bit + 1)) - bit_string->bits_used = bit + 1; - bit_mask = bit_mask << (bit - (byte_number * 8)); - if (value) - bit_string->value[byte_number] |= bit_mask; - else - bit_string->value[byte_number] &= (~(bit_mask)); - } -} - -bool bitstring_bit(BACNET_BIT_STRING * bit_string, uint8_t bit) -{ - bool value = false; - uint8_t byte_number = bit / 8; - uint8_t bit_mask = 1; - - if (bit < (MAX_BITSTRING_BYTES * 8)) { - bit_mask = bit_mask << (bit - (byte_number * 8)); - if (bit_string->value[byte_number] & bit_mask) - value = true; - } - - return value; -} - -uint8_t bitstring_bits_used(BACNET_BIT_STRING * bit_string) -{ - return bit_string->bits_used; -} - -/* returns the number of bytes that a bit string is using */ -int bitstring_bytes_used(BACNET_BIT_STRING * bit_string) -{ - int len = 0; /* return value */ - uint8_t used_bytes = 0; - uint8_t last_bit = 0; - - if (bit_string->bits_used) { - last_bit = bit_string->bits_used - 1; - used_bytes = last_bit / 8; - /* add one for the first byte */ - used_bytes++; - len = used_bytes; - } - - return len; -} - -uint8_t bitstring_octet(BACNET_BIT_STRING * bit_string, uint8_t index) -{ - uint8_t octet = 0; - - if (bit_string) { - if (index < MAX_BITSTRING_BYTES) { - octet = bit_string->value[index]; - } - } - - return octet; -} - -bool bitstring_set_octet(BACNET_BIT_STRING * bit_string, - uint8_t index, uint8_t octet) -{ - bool status = false; - - if (bit_string) { - if (index < MAX_BITSTRING_BYTES) { - bit_string->value[index] = octet; - status = true; - } - } - - return status; -} - -bool bitstring_set_bits_used(BACNET_BIT_STRING * bit_string, - uint8_t bytes_used, uint8_t unused_bits) -{ - bool status = false; - - if (bit_string) { - /* FIXME: check that bytes_used is at least one? */ - bit_string->bits_used = bytes_used * 8; - bit_string->bits_used -= unused_bits; - status = true; - } - - return status; -} - -uint8_t bitstring_bits_capacity(BACNET_BIT_STRING * bit_string) -{ - if (bit_string) - return (sizeof(bit_string->value) * 8); - else - return 0; -} diff --git a/bacnet-stack/src/bacdcode/bitstring_test.c b/bacnet-stack/src/bacdcode/bitstring_test.c deleted file mode 100644 index 0363163d..00000000 --- a/bacnet-stack/src/bacdcode/bitstring_test.c +++ /dev/null @@ -1,70 +0,0 @@ -/*####COPYRIGHTBEGIN#### - ------------------------------------------- - Copyright (C) 2004 Steve Karg - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to: - The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA. - - As a special exception, if other files instantiate templates or - use macros or inline functions from this file, or you compile - this file and link it with other works to produce a work based - on this file, this file does not by itself cause the resulting - work to be covered by the GNU General Public License. However - the source code for this file must still be made available in - accordance with section (3) of the GNU General Public License. - - This exception does not invalidate any other reasons why a work - based on this file might be covered by the GNU General Public - License. - ------------------------------------------- -####COPYRIGHTEND####*/ - -#include -#include -#include /* for strlen */ -#include "bacstr.h" -#include "bits.h" - -#include -#include -#include "ctest.h" - -void testBitString(Test * pTest) -{ - uint8_t bit = 0; - BACNET_BIT_STRING bit_string; - - bitstring_init(&bit_string); - /* verify initialization */ - ct_test(pTest, bitstring_bits_used(&bit_string) == 0); - for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { - ct_test(pTest, bitstring_bit(&bit_string, bit) == false); - } - - /* test for true */ - for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { - bitstring_set_bit(&bit_string, bit, true); - ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); - ct_test(pTest, bitstring_bit(&bit_string, bit) == true); - } - /* test for false */ - bitstring_init(&bit_string); - for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { - bitstring_set_bit(&bit_string, bit, false); - ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); - ct_test(pTest, bitstring_bit(&bit_string, bit) == false); - } -} diff --git a/bacnet-stack/src/bacdcode/characterstring_test.c b/bacnet-stack/src/bacdcode/characterstring_test.c deleted file mode 100644 index 03cd54e9..00000000 --- a/bacnet-stack/src/bacdcode/characterstring_test.c +++ /dev/null @@ -1,100 +0,0 @@ -/*####COPYRIGHTBEGIN#### - ------------------------------------------- - Copyright (C) 2004 Steve Karg - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to: - The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA. - - As a special exception, if other files instantiate templates or - use macros or inline functions from this file, or you compile - this file and link it with other works to produce a work based - on this file, this file does not by itself cause the resulting - work to be covered by the GNU General Public License. However - the source code for this file must still be made available in - accordance with section (3) of the GNU General Public License. - - This exception does not invalidate any other reasons why a work - based on this file might be covered by the GNU General Public - License. - ------------------------------------------- -####COPYRIGHTEND####*/ - -#include -#include -#include /* for strlen */ -#include "bacstr.h" -#include "bits.h" -#include -#include -#include "ctest.h" - -void testCharacterString(Test * pTest) -{ - BACNET_CHARACTER_STRING bacnet_string; - char *value = "Joshua,Mary,Anna,Christopher"; - char test_value[MAX_APDU] = "Patricia"; - char test_append_value[MAX_APDU] = " and the Kids"; - char test_append_string[MAX_APDU] = ""; - bool status = false; - size_t length = 0; - size_t test_length = 0; - size_t i = 0; - - /* verify initialization */ - status = - characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, 0); - ct_test(pTest, status == true); - ct_test(pTest, characterstring_length(&bacnet_string) == 0); - ct_test(pTest, - characterstring_encoding(&bacnet_string) == CHARACTER_ANSI_X34); - /* bounds check */ - status = characterstring_init(&bacnet_string, - CHARACTER_ANSI_X34, - NULL, characterstring_capacity(&bacnet_string) + 1); - ct_test(pTest, status == false); - status = - characterstring_truncate(&bacnet_string, - characterstring_capacity(&bacnet_string) + 1); - ct_test(pTest, status == false); - status = - characterstring_truncate(&bacnet_string, - characterstring_capacity(&bacnet_string)); - ct_test(pTest, status == true); - - test_length = strlen(test_value); - status = characterstring_init(&bacnet_string, - CHARACTER_ANSI_X34, &test_value[0], test_length); - ct_test(pTest, status == true); - value = characterstring_value(&bacnet_string); - length = characterstring_length(&bacnet_string); - ct_test(pTest, length == test_length); - for (i = 0; i < test_length; i++) { - ct_test(pTest, value[i] == test_value[i]); - } - test_length = strlen(test_append_value); - status = characterstring_append(&bacnet_string, - &test_append_value[0], test_length); - strcat(test_append_string, test_value); - strcat(test_append_string, test_append_value); - test_length = strlen(test_append_string); - ct_test(pTest, status == true); - length = characterstring_length(&bacnet_string); - value = characterstring_value(&bacnet_string); - ct_test(pTest, length == test_length); - for (i = 0; i < test_length; i++) { - ct_test(pTest, value[i] == test_append_string[i]); - } -} diff --git a/bacnet-stack/src/bacdcode/main.c b/bacnet-stack/src/bacdcode/main.c deleted file mode 100644 index 992c3682..00000000 --- a/bacnet-stack/src/bacdcode/main.c +++ /dev/null @@ -1,99 +0,0 @@ -/*####COPYRIGHTBEGIN#### - ------------------------------------------- - Copyright (C) 2004 Steve Karg - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to: - The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA. - - As a special exception, if other files instantiate templates or - use macros or inline functions from this file, or you compile - this file and link it with other works to produce a work based - on this file, this file does not by itself cause the resulting - work to be covered by the GNU General Public License. However - the source code for this file must still be made available in - accordance with section (3) of the GNU General Public License. - - This exception does not invalidate any other reasons why a work - based on this file might be covered by the GNU General Public - License. - ------------------------------------------- -####COPYRIGHTEND####*/ - -#include - -#include "bacdef.h" -#include "bacdcode.h" -#include "bacenum.h" -#include "bits.h" -#include "bacstr.h" -#include "bacint.h" - -/* NOTE: byte order plays a role in decoding multibyte values */ -/* http://www.unixpapa.com/incnote/byteorder.html */ -#ifndef BIG_ENDIAN - #error Define BIG_ENDIAN=0 or BIG_ENDIAN=1 for BACnet Stack in compiler settings -#endif - -#include -#include -#include -#include "ctest.h" - -int main(void) -{ - Test *pTest; - bool rc; - - pTest = ct_create("BACDCode", NULL); - /* individual tests */ - rc = ct_addTestFunction(pTest, testBACDCodeTags); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeReal); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeUnsigned); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetUnsigned); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeSigned); - assert(rc); - rc = ct_addTestFunction(pTest, testBACnetSigned); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeEnumerated); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeOctetString); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeCharacterString); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeObject); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeMaxSegsApdu); - assert(rc); - rc = ct_addTestFunction(pTest, testBACDCodeBitString); - assert(rc); - rc = ct_addTestFunction(pTest, testBitString); - assert(rc); - rc = ct_addTestFunction(pTest, testCharacterString); - assert(rc); - rc = ct_addTestFunction(pTest, testOctetString); - assert(rc); - /* configure output */ - ct_setStream(pTest, stdout); - ct_run(pTest); - (void) ct_report(pTest); - ct_destroy(pTest); - - return 0; -} diff --git a/bacnet-stack/src/bacdcode/octetstring.c b/bacnet-stack/src/bacdcode/octetstring.c deleted file mode 100644 index 90c3fab3..00000000 --- a/bacnet-stack/src/bacdcode/octetstring.c +++ /dev/null @@ -1,150 +0,0 @@ -/*####COPYRIGHTBEGIN#### - ------------------------------------------- - Copyright (C) 2004 Steve Karg - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to: - The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA. - - As a special exception, if other files instantiate templates or - use macros or inline functions from this file, or you compile - this file and link it with other works to produce a work based - on this file, this file does not by itself cause the resulting - work to be covered by the GNU General Public License. However - the source code for this file must still be made available in - accordance with section (3) of the GNU General Public License. - - This exception does not invalidate any other reasons why a work - based on this file might be covered by the GNU General Public - License. - ------------------------------------------- -####COPYRIGHTEND####*/ - -#include -#include -#include /* for strlen */ -#include "bacstr.h" -#include "bits.h" - -/* returns false if the string exceeds capacity - initialize by using length=0 */ -bool octetstring_init(BACNET_OCTET_STRING * octet_string, - uint8_t * value, size_t length) -{ - bool status = false; /* return value */ - size_t i; /* counter */ - - if (octet_string) { - octet_string->length = 0; - if (length <= sizeof(octet_string->value)) { - if (value) { - for (i = 0; i < length; i++) { - octet_string->value[octet_string->length] = value[i]; - octet_string->length++; - } - } else { - for (i = 0; i < sizeof(octet_string->value); i++) { - octet_string->value[i] = 0; - } - } - status = true; - } - } - - return status; -} - -bool octetstring_copy(BACNET_OCTET_STRING * dest, - BACNET_OCTET_STRING * src) -{ - return octetstring_init(dest, - octetstring_value(src), octetstring_length(src)); -} - -/* returns false if the string exceeds capacity */ -bool octetstring_append(BACNET_OCTET_STRING * octet_string, - uint8_t * value, size_t length) -{ - size_t i; /* counter */ - bool status = false; /* return value */ - - if (octet_string) { - if ((length + octet_string->length) <= sizeof(octet_string->value)) { - for (i = 0; i < length; i++) { - octet_string->value[octet_string->length] = value[i]; - octet_string->length++; - } - status = true; - } - } - - return status; -} - -/* This function sets a new length without changing the value. - If length exceeds capacity, no modification happens and - function returns false. */ -bool octetstring_truncate(BACNET_OCTET_STRING * octet_string, - size_t length) -{ - bool status = false; /* return value */ - - if (octet_string) { - if (length <= sizeof(octet_string->value)) { - octet_string->length = length; - status = true; - } - } - - return status; -} - -/* returns the length. Returns the value in parameter. */ -uint8_t *octetstring_value(BACNET_OCTET_STRING * octet_string) -{ - uint8_t *value = NULL; - - if (octet_string) { - value = octet_string->value; - } - - return value; -} - -/* returns the length. */ -size_t octetstring_length(BACNET_OCTET_STRING * octet_string) -{ - size_t length = 0; - - if (octet_string) { - /* FIXME: validate length is within bounds? */ - length = octet_string->length; - } - - return length; -} - -/* returns the length. */ -size_t octetstring_capacity(BACNET_OCTET_STRING * octet_string) -{ - size_t length = 0; - - if (octet_string) { - /* FIXME: validate length is within bounds? */ - length = sizeof(octet_string->value); - } - - return length; -} diff --git a/bacnet-stack/src/bacdcode/octetstring_test.c b/bacnet-stack/src/bacdcode/octetstring_test.c deleted file mode 100644 index 1c1a7aab..00000000 --- a/bacnet-stack/src/bacdcode/octetstring_test.c +++ /dev/null @@ -1,103 +0,0 @@ -/*####COPYRIGHTBEGIN#### - ------------------------------------------- - Copyright (C) 2004 Steve Karg - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to: - The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA. - - As a special exception, if other files instantiate templates or - use macros or inline functions from this file, or you compile - this file and link it with other works to produce a work based - on this file, this file does not by itself cause the resulting - work to be covered by the GNU General Public License. However - the source code for this file must still be made available in - accordance with section (3) of the GNU General Public License. - - This exception does not invalidate any other reasons why a work - based on this file might be covered by the GNU General Public - License. - ------------------------------------------- -####COPYRIGHTEND####*/ - -#include -#include -#include /* for strlen */ -#include "bacstr.h" -#include "bits.h" -#include -#include -#include "ctest.h" - -void testOctetString(Test * pTest) -{ - BACNET_OCTET_STRING bacnet_string; - uint8_t *value = NULL; - uint8_t test_value[MAX_APDU] = "Patricia"; - uint8_t test_append_value[MAX_APDU] = " and the Kids"; - uint8_t test_append_string[MAX_APDU] = ""; - bool status = false; - size_t length = 0; - size_t test_length = 0; - size_t i = 0; - - /* verify initialization */ - status = octetstring_init(&bacnet_string, NULL, 0); - ct_test(pTest, status == true); - ct_test(pTest, octetstring_length(&bacnet_string) == 0); - value = octetstring_value(&bacnet_string); - for (i = 0; i < octetstring_capacity(&bacnet_string); i++) { - ct_test(pTest, value[i] == 0); - } - /* bounds check */ - status = octetstring_init(&bacnet_string, NULL, - octetstring_capacity(&bacnet_string) + 1); - ct_test(pTest, status == false); - status = octetstring_init(&bacnet_string, NULL, - octetstring_capacity(&bacnet_string)); - ct_test(pTest, status == true); - status = - octetstring_truncate(&bacnet_string, - octetstring_capacity(&bacnet_string) + 1); - ct_test(pTest, status == false); - status = - octetstring_truncate(&bacnet_string, - octetstring_capacity(&bacnet_string)); - ct_test(pTest, status == true); - - test_length = strlen((char *) test_value); - status = octetstring_init(&bacnet_string, &test_value[0], test_length); - ct_test(pTest, status == true); - length = octetstring_length(&bacnet_string); - value = octetstring_value(&bacnet_string); - ct_test(pTest, length == test_length); - for (i = 0; i < test_length; i++) { - ct_test(pTest, value[i] == test_value[i]); - } - - test_length = strlen((char *) test_append_value); - status = octetstring_append(&bacnet_string, - &test_append_value[0], test_length); - strcat((char *) test_append_string, (char *) test_value); - strcat((char *) test_append_string, (char *) test_append_value); - test_length = strlen((char *) test_append_string); - ct_test(pTest, status == true); - length = octetstring_length(&bacnet_string); - value = octetstring_value(&bacnet_string); - ct_test(pTest, length == test_length); - for (i = 0; i < test_length; i++) { - ct_test(pTest, value[i] == test_append_string[i]); - } -} diff --git a/bacnet-stack/src/bacdcode/bacstr.c b/bacnet-stack/src/bacstr.c similarity index 100% rename from bacnet-stack/src/bacdcode/bacstr.c rename to bacnet-stack/src/bacstr.c diff --git a/bacnet-stack/src/bacdcode/bacstr.mak b/bacnet-stack/test/bacstr.mak similarity index 100% rename from bacnet-stack/src/bacdcode/bacstr.mak rename to bacnet-stack/test/bacstr.mak