pax_global_header00006660000000000000000000000064145504570560014525gustar00rootroot0000000000000052 comment=5a9782588747365d866e4d3c7423fa7330afc89d .clang-format000066400000000000000000000002011455045705600134350ustar00rootroot00000000000000BasedOnStyle: LLVM ColumnLimit: 100 IndentWidth: 4 TabWidth: 4 UseTab: ForContinuationAndIndentation AlignTrailingComments: true .editorconfig000066400000000000000000000004511455045705600135460ustar00rootroot00000000000000# top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file [*] charset = utf-8 trim_trailing_whitespace = true end_of_line = lf insert_final_newline = true # Tab indentation (no size specified) [Makefile] indent_style = tab [*.{c,h,cpp,hpp}] indent_size = 4.gitattributes000066400000000000000000000000261455045705600137620ustar00rootroot00000000000000debian/ export-ignore .github/000077500000000000000000000000001455045705600124315ustar00rootroot00000000000000.github/workflows/000077500000000000000000000000001455045705600144665ustar00rootroot00000000000000.github/workflows/build+test.yml000066400000000000000000000004251455045705600172640ustar00rootroot00000000000000name: build+test on: [push, pull_request] jobs: build_and_test: runs-on: ubuntu-latest steps: - name: install deps run: sudo apt-get install uuid-dev - uses: actions/checkout@v2 - run: make -C sml - run: make -C examples - run: make -C test .github/workflows/check-formatting.yml000066400000000000000000000003771455045705600204450ustar00rootroot00000000000000name: check-formatting on: [push, pull_request] jobs: check-formatting: runs-on: ubuntu-latest steps: - name: install clang-format run: sudo apt-get install clang-format - uses: actions/checkout@v2 - run: ./check-formatting.sh .github/workflows/debuild.yml000066400000000000000000000125041455045705600166230ustar00rootroot00000000000000--- # Basically this is a fragmented bash script name: Debuild Release 'on': release: types: published env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: debuild: runs-on: ubuntu-latest environment: main env: REPO: volkszaehler/volkszaehler-org-project steps: - uses: actions/checkout@v2 - name: Set env # Here we are setting a variable from an expression. run: echo "TAG_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV - name: update repo information run: sudo apt-get update - name: install devscripts run: sudo apt-get install equivs devscripts pipx hub - name: install dependencies run: sudo mk-build-deps -ri - name: debuild run: debuild --no-sign - name: import GPG key # A secret passphrase is used because the key is stored on disk where # it may persist while the passphrase is not. run: | echo -e "$SIGNING_KEY" | \ gpg --batch --passphrase "$SIGNING_PASSPHRASE" --import gpg --list-secret-keys env: SIGNING_KEY: ${{ secrets.SIGNING_KEY }} SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }} - name: debsign run: | debsign -k"$SIGNING_KEY_ID" -p"gpg --batch --pinentry-mode loopback \ --passphrase $SIGNING_PASSPHRASE" env: SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }} # This is not a secret, but we want to have all signing # configuration in one place SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} - name: upload as Release run: | set -x assets=() for asset in ../libsml*.{tar.xz,dsc}; do assets+=("-a" "$asset") done hub release edit "${assets[@]}" -m "$TAG_NAME" "$TAG_NAME" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: upload to Cloudsmith run: | pipx install cloudsmith-cli VERSION="${GITHUB_REF##*/v}" DESCRIPTION_FILE="../libsml_$VERSION.dsc" cloudsmith push deb ${REPO}/debian/any-version "$DESCRIPTION_FILE" \ --sources-file=$(dcmd --orig "$DESCRIPTION_FILE") env: CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }} pbuilder: needs: debuild strategy: matrix: architecture: [armel, armhf, arm64, amd64] distribution: [trixie, bookworm, bullseye] runs-on: ubuntu-latest environment: main env: PBRT: /var/cache/pbuilder REPO: volkszaehler/volkszaehler-org-project steps: - name: update repo information run: sudo apt-get update - name: install pbuilder run: | sudo apt-get install pbuilder qemu-user-static \ debian-archive-keyring pipx hub # Needed for the release download - uses: actions/checkout@v2 - name: Set env # Here we are setting a variable from an expression. run: echo "TAG_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV - name: download source release run: | set -x hub release download "$TAG_NAME" ls -l - name: configure pbuilder run: | echo "MIRRORSITE=http://ftp2.de.debian.org/debian/ HOOKDIR=$PBRT/hooks" | \ sudo tee /root/.pbuilderrc sudo mkdir -p $PBRT/hooks echo "#!/bin/sh apt-get -y install gnupg debian-archive-keyring apt-key adv --keyserver pgp.mit.edu --recv-keys $SIGNING_KEY_ID" | \ sudo tee $PBRT/hooks/G70Keys env: # This is not a secret, but we want to have all signing # configuration in one place SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} - name: create bootstrap run: | sudo pbuilder create --architecture ${{ matrix.architecture }} \ --distribution ${{ matrix.distribution }} \ --debootstrap qemu-debootstrap \ --basetgz $PBRT/current.tgz \ --debootstrapopts \ --keyring=/usr/share/keyrings/debian-archive-keyring.gpg - name: pbuild ${{ matrix.architecture }} ${{ matrix.distribution }} run: | VERSION="${GITHUB_REF##*/v}" sudo pbuilder build \ --architecture ${{ matrix.architecture }} \ --basetgz $PBRT/current.tgz libsml_$VERSION.dsc - name: upload as Release run: | set -x if [[ "${{ matrix.distribution }}" != trixie ]]; then exit fi assets=() for asset in $PBRT/result/libsml*_${{ matrix.architecture }}.{deb,changes,buildinfo}; do assets+=("-a" "$asset") done hub release edit "${assets[@]}" -m "$TAG_NAME" "$TAG_NAME" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: upload to Cloudsmith run: | pipx install cloudsmith-cli VERSION="${GITHUB_REF##*/v}" CHANGES_FILE="$PBRT/result/libsml_${VERSION}_${{ matrix.architecture }}.changes" for DEB in $(dcmd --deb $CHANGES_FILE); do cloudsmith push deb \ ${REPO}/debian/${{ matrix.distribution }} "$DEB" done env: CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }} .github/workflows/test.yml000066400000000000000000000010321455045705600161640ustar00rootroot00000000000000--- name: Workflow Test 'on': workflow_dispatch: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: test: runs-on: ubuntu-latest environment: main steps: - name: import GPG key run: | echo -e "$SIGNING_KEY" | \ gpg --batch --passphrase "SIGNING_PASSPHRASE" --import gpg --list-secret-keys env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SIGNING_KEY: ${{ secrets.SIGNING_KEY }} SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }} .gitignore000066400000000000000000000005231455045705600130610ustar00rootroot00000000000000# Debian Packaging /.pc/ /debian/files /debian/libsml1/ /debian/libsml-dev/ /debian/*.debhelper* /debian/*.substvars # Binaries /test/test /examples/sml_server # Compiled Object files *.slo *.lo *.o # Compiled Dynamic libraries *.so.* *.so *.dylib # Compiled Static libraries *.lai *.la *.a # Editor files *~ *.swp .project .cproject GITHUB_RELEASE.txt000066400000000000000000000003541455045705600137560ustar00rootroot00000000000000 How to do a Github Release To do a Github release that triggers the debuild action you have to create a version tag v. The version must match the version in first line of the debian/changelog. The tag must have a v prefix. LICENSE000066400000000000000000001045131455045705600121020ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 3 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, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . Makefile000066400000000000000000000004761455045705600125400ustar00rootroot00000000000000 all: @$(MAKE) -C sml @$(MAKE) -C examples @$(MAKE) -C test .PHONY: clean install uninstall clean: @$(MAKE) -C sml clean @$(MAKE) -C examples clean @$(MAKE) -C test clean install: all @$(MAKE) -C sml install @$(MAKE) -C examples install uninstall: @$(MAKE) -C sml uninstall @$(MAKE) -C examples uninstall README.md000066400000000000000000000070751455045705600123610ustar00rootroot00000000000000# libSML [![Build Status](https://travis-ci.org/volkszaehler/libsml.svg?branch=master)](https://travis-ci.org/volkszaehler/libsml) [![Join the chat at https://gitter.im/volkszaehler/volkszaehler.org](https://badges.gitter.im/volkszaehler/volkszaehler.org.svg)](https://gitter.im/volkszaehler/volkszaehler.org?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) libSML is a library which implements the Smart Message Language (SML) protocol specified by VDE's Forum Netztechnik/Netzbetrieb (FNN). It can be utilized to communicate to FNN specified Smart Meters or Smart Meter components (EDL/MUC). ### This is the official libSML repo, the original dailab libsml repo on GitHub is dead ### Usage An example how to use libSML is in the examples directory. #### Dependencies Ubuntu apt-get install uuid-dev uuid-runtime #### Compilation make The resulting binaries are located in sml/lib #### Debian Packages [![Hosted By: Cloudsmith](https://img.shields.io/badge/OSS%20hosting%20by-cloudsmith-blue?logo=cloudsmith&style=flat-square)](https://cloudsmith.com) We now build Debian packages for amd64, armhf and arm64 as part of our releases. The ones attached to the release are meant for trixie. These and packages for bookworm and bullseye are also provided through a repository graciously provided by [Cloudsmith](https://cloudsmith.com). The setup of the repository is also [explained by Cloudsmith](https://cloudsmith.io/~volkszaehler/repos/volkszaehler-org-project/setup/#formats-deb). This boils down to adding a file to /etc/apt/sources.list.d/ containing ``` deb [signed-by=/usr/share/keyrings/volkszaehler-volkszaehler-org-project-archive-keyring.gpg] https://dl.cloudsmith.io/public/volkszaehler/volkszaehler-org-project/deb/debian bookworm main deb-src [signed-by=/usr/share/keyrings/volkszaehler-volkszaehler-org-project-archive-keyring.gpg] https://dl.cloudsmith.io/public/volkszaehler/volkszaehler-org-project/deb/debian bookworm main ``` (replace bookworm with your current distro) and retrieving the key as a trusted one ``` curl -1sLf "https://dl.cloudsmith.io/public/volkszaehler/volkszaehler-org-project/gpg.21DBDAC56DF44DA1.key" | \ gpg --dearmor > /usr/share/keyrings/volkszaehler-volkszaehler-org-project-archive-keyring.gpg ``` There is also a libsml package that is part of Debian. While the version in older Debian releases is somewhat outdated the version in trixie is recent. Other than the project packages the official Debian package has a version postfix separated by a hyphen (e.g. 1.0.2-3). It has minor differences in packaging and is maintained as part of the project in the debian branch. #### Testing For testing data have a look at https://github.com/devZer0/libsml-testing ### License Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed - DAI-Labor, TU-Berlin Copyright 2014-2018 libSML contributors libSML 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 3 of the License, or (at your option) any later version. libSML 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. See the file LICENSE for the full license text. ### Thanks Steffen Vogel, Thorben Thuermer, Daniel Pauli, He Bowei #### Thirdparty Acknowledgements This product includes software developed for the Unity Project, by Mike Karlesky, Mark VanderVoord, and Greg Williams and other contributors check-formatting.sh000077500000000000000000000004131455045705600146530ustar00rootroot00000000000000#!/bin/bash set -xe SRCDIRS=(sml) clang-format --version find "${SRCDIRS[@]}" -type f -name '*.h' -o -name '*.cpp' -o -name '*.hpp' | xargs -I{} -P1 clang-format -i -style=file {} [[ -z "$(git status --porcelain "${SRCDIRS[@]}")" ]] || (git status; git diff; false) examples/000077500000000000000000000000001455045705600127075ustar00rootroot00000000000000examples/Makefile000066400000000000000000000013071455045705600143500ustar00rootroot00000000000000UNAME := $(shell uname) CFLAGS += -I../sml/include/ -g -std=c99 -Wall -Wextra -pedantic OBJS = sml_server.o LIBSML = ../sml/lib/libsml.so.1 INSTALL = /usr/bin/install prefix = /usr/local exec_prefix = ${prefix} bindir = ${exec_prefix}/bin libdir = ${exec_prefix}/lib includedir = ${prefix}/include LIBS = -lm ifneq ($(UNAME), Darwin) LIBS += -luuid endif all: sml_server sml_server: $(OBJS) $(LIBSML) $(CC) $(OBJS) $(LIBSML) $(LIBS) -o sml_server %.o: %.c $(CC) $(CFLAGS) -c $^ -o $@ .PHONY: clean install uninstall clean: @rm -f *.o @rm -f sml_server install: sml_server $(INSTALL) -d $(DESTDIR)$(bindir) $(INSTALL) sml_server $(DESTDIR)$(bindir) uninstall: @rm -f $(DESTDIR)$(bindir)/sml_server examples/sml_server.c000066400000000000000000000141331455045705600152360ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // Thanks to Thomas Binder and Axel (tuxedo) for providing code how to // print OBIS data (see transport_receiver()). // https://community.openhab.org/t/using-a-power-meter-sml-with-openhab/21923 // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "unit.h" // globals int sflag = false; // flag to process only a single OBIS data stream int vflag = false; // verbose flag int serial_port_open(const char* device) { int bits; struct termios config; memset(&config, 0, sizeof(config)); if (!strcmp(device, "-")) return 0; // read stdin when "-" is given for the device #ifdef O_NONBLOCK int fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK); #else int fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); #endif if (fd < 0) { fprintf(stderr, "error: open(%s): %s\n", device, strerror(errno)); return -1; } // set RTS ioctl(fd, TIOCMGET, &bits); bits |= TIOCM_RTS; ioctl(fd, TIOCMSET, &bits); tcgetattr(fd, &config); // set 8-N-1 config.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); config.c_oflag &= ~OPOST; config.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); config.c_cflag &= ~(CSIZE | PARENB | PARODD | CSTOPB); config.c_cflag |= CS8; // set speed to 9600 baud cfsetispeed(&config, B9600); cfsetospeed(&config, B9600); tcsetattr(fd, TCSANOW, &config); return fd; } void transport_receiver(unsigned char *buffer, size_t buffer_len) { int i; // the buffer contains the whole message, with transport escape sequences. // these escape sequences are stripped here. sml_file *file = sml_file_parse(buffer + 8, buffer_len - 16); // the sml file is parsed now // this prints some information about the file if (vflag) sml_file_print(file); // read here some values ... if (vflag) printf("OBIS data\n"); for (i = 0; i < file->messages_len; i++) { sml_message *message = file->messages[i]; if (*message->message_body->tag == SML_MESSAGE_GET_LIST_RESPONSE) { sml_list *entry; sml_get_list_response *body; body = (sml_get_list_response *) message->message_body->data; for (entry = body->val_list; entry != NULL; entry = entry->next) { if (!entry->value) { // do not crash on null value fprintf(stderr, "Error in data stream. entry->value should not be NULL. Skipping this.\n"); continue; } if (entry->value->type == SML_TYPE_OCTET_STRING) { char *str; printf("%d-%d:%d.%d.%d*%d#%s#\n", entry->obj_name->str[0], entry->obj_name->str[1], entry->obj_name->str[2], entry->obj_name->str[3], entry->obj_name->str[4], entry->obj_name->str[5], sml_value_to_strhex(entry->value, &str, true)); free(str); } else if (entry->value->type == SML_TYPE_BOOLEAN) { printf("%d-%d:%d.%d.%d*%d#%s#\n", entry->obj_name->str[0], entry->obj_name->str[1], entry->obj_name->str[2], entry->obj_name->str[3], entry->obj_name->str[4], entry->obj_name->str[5], entry->value->data.boolean ? "true" : "false"); } else if (((entry->value->type & SML_TYPE_FIELD) == SML_TYPE_INTEGER) || ((entry->value->type & SML_TYPE_FIELD) == SML_TYPE_UNSIGNED)) { double value = sml_value_to_double(entry->value); int scaler = (entry->scaler) ? *entry->scaler : 0; int prec = -scaler; if (prec < 0) prec = 0; value = value * pow(10, scaler); printf("%d-%d:%d.%d.%d*%d#%.*f#", entry->obj_name->str[0], entry->obj_name->str[1], entry->obj_name->str[2], entry->obj_name->str[3], entry->obj_name->str[4], entry->obj_name->str[5], prec, value); const char *unit = NULL; if (entry->unit && // do not crash on null (unit is optional) (unit = dlms_get_unit((unsigned char) *entry->unit)) != NULL) printf("%s", unit); printf("\n"); // flush the stdout puffer, that pipes work without waiting fflush(stdout); } } if (sflag) exit(0); // processed first message - exit } } // free the malloc'd memory sml_file_free(file); } int main(int argc, char *argv[]) { // this example assumes that a EDL21 meter sending SML messages via a // serial device. Adjust as needed. int c; while ((c = getopt(argc, argv, "+hsv")) != -1) { switch (c) { case 'h': printf("usage: %s [-h] [-s] [-v] device\n", argv[0]); printf("device - serial device of connected power meter e.g. /dev/cu.usbserial, or - for stdin\n"); printf("-h - help\n"); printf("-s - process only one OBIS data stream (single)\n"); printf("-v - verbose\n"); exit(0); // exit here break; case 's': sflag = true; break; case 'v': vflag = true; break; case '?': // get a not specified switch, error message is printed by getopt() printf("Use %s -h for help.\n", argv[0]); exit(1); // exit here break; default: break; } } if (argc - optind != 1) { printf("error: Arguments mismatch.\nUse %s -h for help.\n", argv[0]); exit(1); // exit here } // open serial port int fd = serial_port_open(argv[optind]); if (fd < 0) { // error message is printed by serial_port_open() exit(1); } // listen on the serial device, this call is blocking. sml_transport_listen(fd, &transport_receiver); close(fd); return 0; } examples/unit.h000066400000000000000000000115471455045705600140470ustar00rootroot00000000000000/** * DLMS Units as specified in ISO EN 62056-62 and used by SML * * @package libsml * @copyright Copyright (c) 2011, The volkszaehler.org project * @license http://www.gnu.org/licenses/gpl.txt GNU Public License * @author Steffen Vogel */ /* * This file is part of volkzaehler.org * * volkzaehler.org 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 3 of the License, or * any later version. * * volkzaehler.org 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 volkszaehler.org. If not, see . */ typedef struct { unsigned char code; const char *unit; } dlms_unit_t; /** * Static lookup table */ dlms_unit_t dlms_units[] = { // code, unit // Quantity Unit name SI definition (comment) //===================================================================================================== {1, "a"}, // time year 52*7*24*60*60 s {2, "mo"}, // time month 31*24*60*60 s {3, "wk"}, // time week 7*24*60*60 s {4, "d"}, // time day 24*60*60 s {5, "h"}, // time hour 60*60 s {6, "min."}, // time min 60 s {7, "s"}, // time (t) second s {8, "°"}, // (phase) angle degree rad*180/π {9, "°C"}, // temperature (T) degree celsius K-273.15 {10, "currency"}, // (local) currency {11, "m"}, // length (l) metre m {12, "m/s"}, // speed (v) metre per second m/s {13, "m³"}, // volume (V) cubic metre m³ {14, "m³"}, // corrected volume cubic metre m³ {15, "m³/h"}, // volume flux cubic metre per hour m³/(60*60s) {16, "m³/h"}, // corrected volume flux cubic metre per hour m³/(60*60s) {17, "m³/d"}, // volume flux m³/(24*60*60s) {18, "m³/d"}, // corrected volume flux m³/(24*60*60s) {19, "l"}, // volume litre 10-3 m³ {20, "kg"}, // mass (m) kilogram {21, "N"}, // force (F) newton {22, "Nm"}, // energy newtonmeter J = Nm = Ws {23, "Pa"}, // pressure (p) pascal N/m² {24, "bar"}, // pressure (p) bar 10⁵ N/m² {25, "J"}, // energy joule J = Nm = Ws {26, "J/h"}, // thermal power joule per hour J/(60*60s) {27, "W"}, // active power (P) watt W = J/s {28, "VA"}, // apparent power (S) volt-ampere {29, "var"}, // reactive power (Q) var {30, "Wh"}, // active energy watt-hour W*(60*60s) {31, "VAh"}, // apparent energy volt-ampere-hour VA*(60*60s) {32, "varh"}, // reactive energy var-hour var*(60*60s) {33, "A"}, // current (I) ampere A {34, "C"}, // electrical charge (Q) coulomb C = As {35, "V"}, // voltage (U) volt V {36, "V/m"}, // electr. field strength (E) volt per metre {37, "F"}, // capacitance (C) farad C/V = As/V {38, "Ω"}, // resistance (R) ohm Ω = V/A {39, "Ωm²/m"}, // resistivity (ρ) Ωm {40, "Wb"}, // magnetic flux (Φ) weber Wb = Vs {41, "T"}, // magnetic flux density (B) tesla Wb/m2 {42, "A/m"}, // magnetic field strength (H) ampere per metre A/m {43, "H"}, // inductance (L) henry H = Wb/A {44, "Hz"}, // frequency (f, ω) hertz 1/s {45, "1/(Wh)"}, // R_W (Active energy meter constant or pulse value) {46, "1/(varh)"}, // R_B (reactive energy meter constant or pulse value) {47, "1/(VAh)"}, // R_S (apparent energy meter constant or pulse value) {48, "V²h"}, // volt-squared hour volt-squaredhours V²(60*60s) {49, "A²h"}, // ampere-squared hour ampere-squaredhours A²(60*60s) {50, "kg/s"}, // mass flux kilogram per second kg/s {51, "S, mho"}, // conductance siemens 1/Ω {52, "K"}, // temperature (T) kelvin {53, "1/(V²h)"}, // R_U²h (Volt-squared hour meter constant or pulse value) {54, "1/(A²h)"}, // R_I²h (Ampere-squared hour meter constant or pulse value) {55, "1/m³"}, // R_V, meter constant or pulse value (volume) {56, "%"}, // percentage % {57, "Ah"}, // ampere-hours ampere-hour {60, "Wh/m³"}, // energy per volume 3,6*103 J/m³ {61, "J/m³"}, // calorific value, wobbe {62, "Mol %"}, // molar fraction of mole percent (Basic gas composition unit) // gas composition {63, "g/m³"}, // mass density, quantity of material (Gas analysis, accompanying elements) {64, "Pa s"}, // dynamic viscosity pascal second (Characteristic of gas stream) {253, "(reserved)"}, // reserved {254, "(other)"}, // other unit {255, "(unitless)"}, // no unit, unitless, count {0, ""} // stop condition for iterator }; const char * dlms_get_unit(unsigned char code) { dlms_unit_t *it = dlms_units; do { // linear search if (it->code == code) { return it->unit; } } while ((++it)->code); return NULL; // not found } library.json000066400000000000000000000007541455045705600134360ustar00rootroot00000000000000{ "name": "libSML", "keywords": "sml, smartmeter, smart message language, smart meter", "description": "Implementation in C of the Smart Message Language (SML) protocol", "repository": { "type": "git", "url": "https://github.com/volkszaehler/libsml" }, "build": { "includeDir": "sml/include", "srcDir": "sml/src", "flags": "-DSML_NO_UUID_LIB" }, "version": "1.1.2", "frameworks": "arduino", "platforms": "*" } sml.pc000066400000000000000000000005011455045705600122040ustar00rootroot00000000000000prefix=/usr exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include Name: libSML Description: Library for the Smart Messaging Language (SML) Version: 1.1.2 URL: http://github.com/volkszaehler/libsml Requires: uuid >= 2.16 Libs: -L${libdir} -lsml Libs.private: -luuid -lm Cflags: -I${includedir}/sml sml/000077500000000000000000000000001455045705600116645ustar00rootroot00000000000000sml/Makefile000066400000000000000000000044071455045705600133310ustar00rootroot00000000000000UNAME := $(shell uname) CFLAGS += -I./include/ -fPIC -fno-stack-protector -g -std=c99 -Wall -Wextra -pedantic # Available Flags: # SML_NO_UUID_LIB - compile without uuid lib ifneq ($(UNAME), Darwin) LIBS=-luuid endif NAME=libsml SOVERSION=1 ifeq ($(UNAME), Darwin) SONAME=$(NAME).$(SOVERSION).dylib else SONAME=$(NAME).so.$(SOVERSION) endif LDFLAGS += -Wl,-soname=$(SONAME) -shared LIB_DIR=./lib INC_DIR=./include OBJ_LIB=$(LIB_DIR)/$(NAME).o DYN_LIB=$(LIB_DIR)/$(SONAME) ST_LIB=$(LIB_DIR)/$(NAME).a INSTALL = /usr/bin/install prefix = /usr/local exec_prefix = ${prefix} bindir = ${exec_prefix}/bin libdir = ${exec_prefix}/lib includedir = ${prefix}/include OBJS = \ src/sml_file.o \ src/sml_attention_response.o \ src/sml_transport.o \ src/sml_octet_string.o \ src/sml_shared.o \ src/sml_number.o \ src/sml_message.o \ src/sml_time.o \ src/sml_list.o \ src/sml_status.o \ src/sml_value.o \ src/sml_tree.o \ src/sml_boolean.o \ src/sml_crc16.o \ src/sml_open_request.o \ src/sml_open_response.o \ src/sml_get_list_request.o \ src/sml_get_list_response.o \ src/sml_close_request.o \ src/sml_close_response.o \ src/sml_set_proc_parameter_request.o \ src/sml_get_proc_parameter_request.o \ src/sml_get_proc_parameter_response.o \ src/sml_get_profile_pack_request.o \ src/sml_get_profile_pack_response.o \ src/sml_get_profile_list_request.o \ src/sml_get_profile_list_response.o all: libsml libsml: $(DYN_LIB) $(ST_LIB) $(OBJ_LIB) $(DYN_LIB): $(OBJS) ifeq ($(UNAME), Darwin) $(CC) $(LIBS) -dynamiclib -install_name $(SONAME) -o $@ $^ else $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) endif $(OBJ_LIB): $(OBJS) $(LD) -r -o $@ $^ $(ST_LIB): $(OBJS) $(AR) -rs $@ $^ .PHONY: clean install uninstall clean: @rm -f src/*.o @rm -f $(DYN_LIB) $(OBJ_LIB) $(ST_LIB) install: $(DYN_LIB) $(ST_LIB) install -d $(DESTDIR)$(libdir) $(INSTALL) $(DYN_LIB) $(ST_LIB) $(DESTDIR)$(libdir) ifeq ($(UNAME), Darwin) @cd $(DESTDIR)$(libdir); ln -sf $(SONAME) $(NAME).dylib else @cd $(DESTDIR)$(libdir); ln -sf $(SONAME) $(NAME).so endif install -d $(DESTDIR)$(includedir) cp -a $(INC_DIR)/* $(DESTDIR)$(includedir) uninstall: @rm -f $(DESTDIR)$(libdir)/$(SONAME) $(DESTDIR)$(libdir)/$(NAME).so $(DESTDIR)$(libdir)/$(NAME).dylib $(DESTDIR)$(libdir)/$(NAME).a @rm -rf $(DESTDIR)$(includedir)/sml sml/include/000077500000000000000000000000001455045705600133075ustar00rootroot00000000000000sml/include/sml/000077500000000000000000000000001455045705600141025ustar00rootroot00000000000000sml/include/sml/sml_attention_response.h000066400000000000000000000026771455045705600210650ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_ATTENTION_RESPONSE_H_ #define SML_ATTENTION_RESPONSE_H_ #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; octet_string *attention_number; octet_string *attention_message; // optional sml_tree *attention_details; // optional } sml_attention_response; sml_attention_response *sml_attention_response_init(); sml_attention_response *sml_attention_response_parse(sml_buffer *buf); void sml_attention_response_write(sml_attention_response *msg, sml_buffer *buf); void sml_attention_response_free(sml_attention_response *msg); #ifdef __cplusplus } #endif #endif /* SML_ATTENTION_RESPONSE_H_ */ sml/include/sml/sml_boolean.h000066400000000000000000000022541455045705600165500ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_BOOLEAN_H_ #define SML_BOOLEAN_H_ #define SML_BOOLEAN_TRUE 0xFF #define SML_BOOLEAN_FALSE 0x00 #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif typedef u8 sml_boolean; sml_boolean *sml_boolean_init(u8 b); sml_boolean *sml_boolean_parse(sml_buffer *buf); void sml_boolean_write(sml_boolean *boolean, sml_buffer *buf); void sml_boolean_free(sml_boolean *b); #ifdef __cplusplus } #endif #endif /* SML_BOOLEAN_H_ */ sml/include/sml/sml_close_request.h000066400000000000000000000024041455045705600200030ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_CLOSE_REQUEST_H_ #define SML_CLOSE_REQUEST_H_ #include "sml_octet_string.h" #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif typedef struct { sml_signature *global_signature; // optional } sml_close_request; sml_close_request *sml_close_request_init(); sml_close_request *sml_close_request_parse(sml_buffer *buf); void sml_close_request_write(sml_close_request *msg, sml_buffer *buf); void sml_close_request_free(sml_close_request *msg); #ifdef __cplusplus } #endif #endif /* SML_CLOSE_REQUEST_H_ */ sml/include/sml/sml_close_response.h000066400000000000000000000023221455045705600201500ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_CLOSE_RESPONSE_H_ #define SML_CLOSE_RESPONSE_H_ #include "sml_close_request.h" #ifdef __cplusplus extern "C" { #endif typedef sml_close_request sml_close_response; sml_close_response *sml_close_response_init(); sml_close_response *sml_close_response_parse(sml_buffer *buf); void sml_close_response_write(sml_close_response *msg, sml_buffer *buf); void sml_close_response_free(sml_close_response *msg); #ifdef __cplusplus } #endif #endif /* SML_CLOSE_RESPONSE_H_ */ sml/include/sml/sml_crc16.h000066400000000000000000000022321455045705600160430ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_CRC16_H_ #define SML_CRC16_H_ #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif // CRC16 FSC implementation based on DIN 62056-46 u16 sml_crc16_calculate(unsigned char *cp, int len); // CRC-16/CCITT(Kermit) implementation poly=0x1021 init=0x0000 refin=true refout=true xorout=0x0000 u16 sml_crc16kermit_calculate(unsigned char *cp, int len); #ifdef __cplusplus } #endif #endif /* SML_CRC16_H_ */ sml/include/sml/sml_file.h000066400000000000000000000025561455045705600160550ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_FILE_H_ #define SML_FILE_H_ #include "sml_message.h" #include "sml_shared.h" #include #ifdef __cplusplus extern "C" { #endif // a SML file consist of multiple SML messages typedef struct { sml_message **messages; short messages_len; sml_buffer *buf; } sml_file; sml_file *sml_file_init(); // parses a SML file. sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len); void sml_file_add_message(sml_file *file, sml_message *message); void sml_file_write(sml_file *file); void sml_file_free(sml_file *file); void sml_file_print(sml_file *file); #ifdef __cplusplus } #endif #endif /* SML_FILE_H_ */ sml/include/sml/sml_get_list_request.h000066400000000000000000000027301455045705600205120ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_GET_LIST_REQUEST_H_ #define SML_GET_LIST_REQUEST_H_ #include "sml_list.h" #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_time.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *client_id; octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional octet_string *list_name; // optional } sml_get_list_request; sml_get_list_request *sml_get_list_request_init(); sml_get_list_request *sml_get_list_request_parse(sml_buffer *buf); void sml_get_list_request_write(sml_get_list_request *msg, sml_buffer *buf); void sml_get_list_request_free(sml_get_list_request *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_LIST_REQUEST_H_ */ sml/include/sml/sml_get_list_response.h000066400000000000000000000030571455045705600206630ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_GET_LIST_RESPONSE_H_ #define SML_GET_LIST_RESPONSE_H_ #include "sml_list.h" #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_time.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *client_id; // optional octet_string *server_id; octet_string *list_name; // optional sml_time *act_sensor_time; // optional sml_list *val_list; sml_signature *list_signature; // optional sml_time *act_gateway_time; // optional } sml_get_list_response; sml_get_list_response *sml_get_list_response_init(); sml_get_list_response *sml_get_list_response_parse(sml_buffer *buf); void sml_get_list_response_write(sml_get_list_response *msg, sml_buffer *buf); void sml_get_list_response_free(sml_get_list_response *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_LIST_RESPONSE_H_ */ sml/include/sml/sml_get_proc_parameter_request.h000066400000000000000000000031051455045705600225370ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_GET_PROC_PARAMETER_REQUEST_H_ #define SML_GET_PROC_PARAMETER_REQUEST_H_ #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional sml_tree_path *parameter_tree_path; octet_string *attribute; // optional } sml_get_proc_parameter_request; sml_get_proc_parameter_request *sml_get_proc_parameter_request_init(); sml_get_proc_parameter_request *sml_get_proc_parameter_request_parse(sml_buffer *buf); void sml_get_proc_parameter_request_write(sml_get_proc_parameter_request *msg, sml_buffer *buf); void sml_get_proc_parameter_request_free(sml_get_proc_parameter_request *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_PROC_PARAMETER_REQUEST_H_ */ sml/include/sml/sml_get_proc_parameter_response.h000066400000000000000000000027561455045705600227200ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_GET_PROC_PARAMETER_RESPONSE_H_ #define SML_GET_PROC_PARAMETER_RESPONSE_H_ #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; sml_tree_path *parameter_tree_path; sml_tree *parameter_tree; } sml_get_proc_parameter_response; sml_get_proc_parameter_response *sml_get_proc_parameter_response_init(); sml_get_proc_parameter_response *sml_get_proc_parameter_response_parse(sml_buffer *buf); void sml_get_proc_parameter_response_write(sml_get_proc_parameter_response *msg, sml_buffer *buf); void sml_get_proc_parameter_response_free(sml_get_proc_parameter_response *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_PROC_PARAMETER_RESPONSE_H_ */ sml/include/sml/sml_get_profile_list_request.h000066400000000000000000000027151455045705600222350ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_GET_PROFILE_LIST_REQUEST_H_ #define SML_GET_PROFILE_LIST_REQUEST_H_ #include "sml_get_profile_pack_request.h" #ifdef __cplusplus extern "C" { #endif // Apparently SML_GetProfilePack.Req is the same as SML_GetProfileList.Req typedef sml_get_profile_pack_request sml_get_profile_list_request; #define sml_get_profile_list_request_init() sml_get_profile_pack_request_init() #define sml_get_profile_list_request_parse(buf) sml_get_profile_pack_request_parse(buf) #define sml_get_profile_list_request_write(msg, buf) sml_get_profile_pack_request_write(msg, buf) #define sml_get_profile_list_request_free(msg) sml_get_profile_pack_request_free(msg) #ifdef __cplusplus } #endif #endif /* SML_GET_PROFILE_LIST_REQUEST_H_ */ sml/include/sml/sml_get_profile_list_response.h000066400000000000000000000032071455045705600224000ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_GET_PROFILE_LIST_RESPONSE_H_ #define SML_GET_PROFILE_LIST_RESPONSE_H_ #include "sml_list.h" #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_time.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; sml_time *act_time; u32 *reg_period; sml_tree_path *parameter_tree_path; sml_time *val_time; u64 *status; sml_sequence *period_list; octet_string *rawdata; sml_signature *period_signature; } sml_get_profile_list_response; sml_get_profile_list_response *sml_get_profile_list_response_init(); sml_get_profile_list_response *sml_get_profile_list_response_parse(sml_buffer *buf); void sml_get_profile_list_response_write(sml_get_profile_list_response *msg, sml_buffer *buf); void sml_get_profile_list_response_free(sml_get_profile_list_response *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_PROFILE_LIST_RESPONSE_H_ */ sml/include/sml/sml_get_profile_pack_request.h000066400000000000000000000042601455045705600221750ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_GET_PROFILE_PACK_REQUEST_H_ #define SML_GET_PROFILE_PACK_REQUEST_H_ #include "sml_list.h" #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_time.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef octet_string sml_obj_req_entry; #define sml_obj_req_entry_parse(buf) sml_octet_string_parse(buf) #define sml_obj_req_entry_write(p, buf) sml_octet_string_write(p, buf) #define sml_obj_req_entry_free(p) sml_octet_string_free(p) typedef struct sml_obj_req_entry_list_entry { sml_obj_req_entry *object_list_entry; // list specific struct sml_obj_req_entry_list_entry *next; } sml_obj_req_entry_list; typedef struct { octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional sml_boolean *with_rawdata; // optional sml_time *begin_time; // optional sml_time *end_time; // optional sml_tree_path *parameter_tree_path; sml_obj_req_entry_list *object_list; // optional sml_tree *das_details; // optional } sml_get_profile_pack_request; sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf); sml_get_profile_pack_request *sml_get_profile_pack_request_init(); void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_buffer *buf); void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg); #ifdef __cplusplus } #endif #endif /* SML_GET_PROFILE_PACK_REQUEST_H_ */ sml/include/sml/sml_get_profile_pack_response.h000066400000000000000000000056601455045705600223500ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_GET_PROFILE_PACK_RESPONSE_H_ #define SML_GET_PROFILE_PACK_RESPONSE_H_ #include "sml_list.h" #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_time.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; sml_time *act_time; // specified by germans (current time was meant) ;) u32 *reg_period; sml_tree_path *parameter_tree_path; sml_sequence *header_list; // list of sml_prof_obj_header_entry sml_sequence *period_list; // list of sml_prof_obj_period_entry octet_string *rawdata; // optional sml_signature *profile_signature; // optional } sml_get_profile_pack_response; sml_get_profile_pack_response *sml_get_profile_pack_response_init(); sml_get_profile_pack_response *sml_get_profile_pack_response_parse(sml_buffer *buf); void sml_get_profile_pack_response_write(sml_get_profile_pack_response *msg, sml_buffer *buf); void sml_get_profile_pack_response_free(sml_get_profile_pack_response *msg); typedef struct { octet_string *obj_name; sml_unit *unit; i8 *scaler; } sml_prof_obj_header_entry; sml_prof_obj_header_entry *sml_prof_obj_header_entry_init(); sml_prof_obj_header_entry *sml_prof_obj_header_entry_parse(sml_buffer *buf); void sml_prof_obj_header_entry_write(sml_prof_obj_header_entry *entry, sml_buffer *buf); void sml_prof_obj_header_entry_free(sml_prof_obj_header_entry *entry); typedef struct { sml_time *val_time; u64 *status; sml_sequence *value_list; sml_signature *period_signature; } sml_prof_obj_period_entry; sml_prof_obj_period_entry *sml_prof_obj_period_entry_init(); sml_prof_obj_period_entry *sml_prof_obj_period_entry_parse(sml_buffer *buf); void sml_prof_obj_period_entry_write(sml_prof_obj_period_entry *entry, sml_buffer *buf); void sml_prof_obj_period_entry_free(sml_prof_obj_period_entry *entry); typedef struct { sml_value *value; sml_signature *value_signature; } sml_value_entry; sml_value_entry *sml_value_entry_init(); sml_value_entry *sml_value_entry_parse(sml_buffer *buf); void sml_value_entry_write(sml_value_entry *entry, sml_buffer *buf); void sml_value_entry_free(sml_value_entry *entry); #ifdef __cplusplus } #endif #endif /* SML_GET_PROFILE_PACK_RESPONSE_H_ */ sml/include/sml/sml_list.h000066400000000000000000000040041455045705600160770ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_LIST_H_ #define SML_LIST_H_ #include "sml_number.h" #include "sml_octet_string.h" #include "sml_status.h" #include "sml_time.h" #include "sml_value.h" #ifdef __cplusplus extern "C" { #endif typedef struct { void **elems; int elems_len; void (*elem_free)(void *elem); } sml_sequence; sml_sequence *sml_sequence_init(void (*elem_free)(void *elem)); sml_sequence *sml_sequence_parse(sml_buffer *buf, void *(*elem_parse)(sml_buffer *buf), void (*elem_free)(void *elem)); void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write)(void *elem, sml_buffer *buf)); void sml_sequence_free(sml_sequence *seq); void sml_sequence_add(sml_sequence *list, void *new_entry); typedef struct sml_list_entry { octet_string *obj_name; sml_status *status; // optional sml_time *val_time; // optional sml_unit *unit; // optional i8 *scaler; // optional sml_value *value; sml_signature *value_signature; // optional // list specific struct sml_list_entry *next; } sml_list; sml_list *sml_list_init(); sml_list *sml_list_parse(sml_buffer *buf); void sml_list_write(sml_list *list, sml_buffer *buf); void sml_list_add(sml_list *list, sml_list *new_entry); void sml_list_free(sml_list *list); #ifdef __cplusplus } #endif #endif /* SML_LIST_H_ */ sml/include/sml/sml_message.h000066400000000000000000000062441455045705600165600ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_MESSAGE_H_ #define SML_MESSAGE_H_ #include "sml_list.h" #include "sml_octet_string.h" #include "sml_time.h" #include "sml_tree.h" #include #include "sml_attention_response.h" #include "sml_close_request.h" #include "sml_close_response.h" #include "sml_get_list_request.h" #include "sml_get_list_response.h" #include "sml_get_proc_parameter_request.h" #include "sml_get_proc_parameter_response.h" #include "sml_get_profile_list_request.h" #include "sml_get_profile_list_response.h" #include "sml_get_profile_pack_request.h" #include "sml_get_profile_pack_response.h" #include "sml_open_request.h" #include "sml_open_response.h" #include "sml_set_proc_parameter_request.h" // clang-format off #define SML_MESSAGE_OPEN_REQUEST 0x00000100 #define SML_MESSAGE_OPEN_RESPONSE 0x00000101 #define SML_MESSAGE_CLOSE_REQUEST 0x00000200 #define SML_MESSAGE_CLOSE_RESPONSE 0x00000201 #define SML_MESSAGE_GET_PROFILE_PACK_REQUEST 0x00000300 #define SML_MESSAGE_GET_PROFILE_PACK_RESPONSE 0x00000301 #define SML_MESSAGE_GET_PROFILE_LIST_REQUEST 0x00000400 #define SML_MESSAGE_GET_PROFILE_LIST_RESPONSE 0x00000401 #define SML_MESSAGE_GET_PROC_PARAMETER_REQUEST 0x00000500 #define SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE 0x00000501 #define SML_MESSAGE_SET_PROC_PARAMETER_REQUEST 0x00000600 #define SML_MESSAGE_SET_PROC_PARAMETER_RESPONSE 0x00000601 // This doesn't exist in the spec #define SML_MESSAGE_GET_LIST_REQUEST 0x00000700 #define SML_MESSAGE_GET_LIST_RESPONSE 0x00000701 #define SML_MESSAGE_ATTENTION_RESPONSE 0x0000FF01 // clang-format on #ifdef __cplusplus extern "C" { #endif typedef struct { u32 *tag; void *data; } sml_message_body; typedef struct { octet_string *transaction_id; u8 *group_id; u8 *abort_on_error; sml_message_body *message_body; u16 *crc; /* end of message */ } sml_message; // SML MESSAGE sml_message *sml_message_parse(sml_buffer *buf); sml_message *sml_message_init(); // Sets a transaction id. void sml_message_free(sml_message *msg); void sml_message_write(sml_message *msg, sml_buffer *buf); // SML_MESSAGE_BODY sml_message_body *sml_message_body_parse(sml_buffer *buf); sml_message_body *sml_message_body_init(u32 tag, void *data); void sml_message_body_free(sml_message_body *message_body); void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf); #ifdef __cplusplus } #endif #endif /* SML_MESSAGE_H_ */ sml/include/sml/sml_number.h000066400000000000000000000100221455045705600164110ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_NUMBER_H_ #define SML_NUMBER_H_ #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif void *sml_number_init(u64 number, unsigned char type, int size); // Parses a number. Identified by type (SML_TYPE_INTEGER or SML_TYPE_UNSIGNED) // and maximal number of bytes (SML_TYPE_NUMBER_8, SML_TYPE_NUMBER_16, // SML_TYPE_NUMBER_32, SML_TYPE_NUMBER_64) void *sml_number_parse(sml_buffer *buf, unsigned char type, int max_size); void sml_number_write(void *np, unsigned char type, int size, sml_buffer *buf); void sml_number_free(void *np); #define sml_u8_init(n) (u8 *)sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8) #define sml_u16_init(n) (u16 *)sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16) #define sml_u32_init(n) (u32 *)sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32) #define sml_u64_init(n) (u64 *)sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64) #define sml_i8_init(n) (i8 *)sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8) #define sml_i16_init(n) (i16 *)sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16) #define sml_i32_init(n) (i32 *)sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32) #define sml_i64_init(n) (i64 *)sml_number_init(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64) #define sml_u8_parse(buf) (u8 *)sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8) #define sml_u16_parse(buf) (u16 *)sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16) #define sml_u32_parse(buf) (u32 *)sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32) #define sml_u64_parse(buf) (u64 *)sml_number_parse(buf, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64) #define sml_i8_parse(buf) (i8 *)sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8) #define sml_i16_parse(buf) (i16 *)sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16) #define sml_i32_parse(buf) (i32 *)sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32) #define sml_i64_parse(buf) (i64 *)sml_number_parse(buf, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64) #define sml_u8_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8, buf) #define sml_u16_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16, buf) #define sml_u32_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_32, buf) #define sml_u64_write(n, buf) sml_number_write(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_64, buf) #define sml_i8_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_8, buf) #define sml_i16_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_16, buf) #define sml_i32_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_32, buf) #define sml_i64_write(n, buf) sml_number_write(n, SML_TYPE_INTEGER, SML_TYPE_NUMBER_64, buf) #define sml_u8_free(n) sml_number_free(n) #define sml_u16_free(n) sml_number_free(n) #define sml_u32_free(n) sml_number_free(n) #define sml_u64_free(n) sml_number_free(n) #define sml_i8_free(n) sml_number_free(n) #define sml_i16_free(n) sml_number_free(n) #define sml_i32_free(n) sml_number_free(n) #define sml_i64_free(n) sml_number_free(n) typedef u8 sml_unit; #define sml_unit_init(n) sml_u8_init(n) #define sml_unit_parse(buf) sml_u8_parse(buf) #define sml_unit_write(n, buf) sml_u8_write(n, buf) #define sml_unit_free(np) sml_number_free(np) #ifdef __cplusplus } #endif #endif /* SML_NUMBER_H_ */ sml/include/sml/sml_octet_string.h000066400000000000000000000034311455045705600176330ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_OCTET_STRING_H_ #define SML_OCTET_STRING_H_ #include "sml_shared.h" #include #ifdef __cplusplus extern "C" { #endif typedef struct { unsigned char *str; int len; } octet_string; octet_string *sml_octet_string_init(unsigned char *str, int length); octet_string *sml_octet_string_init_from_hex(char *str); // Parses a octet string, updates the buffer accordingly, memory must be free'd elsewhere. octet_string *sml_octet_string_parse(sml_buffer *buf); octet_string *sml_octet_string_generate_uuid(); void sml_octet_string_write(octet_string *str, sml_buffer *buf); void sml_octet_string_free(octet_string *str); int sml_octet_string_cmp(octet_string *s1, octet_string *s2); int sml_octet_string_cmp_with_hex(octet_string *str, char *hex); // sml signature typedef octet_string sml_signature; #define sml_signature_parse(buf) sml_octet_string_parse(buf) #define sml_signature_write(s, buf) sml_octet_string_write(s, buf) #define sml_signature_free(s) sml_octet_string_free(s) #ifdef __cplusplus } #endif #endif /* SML_OCTET_STRING_H_ */ sml/include/sml/sml_open_request.h000066400000000000000000000026751455045705600176510ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_OPEN_REQUEST_H_ #define SML_OPEN_REQUEST_H_ #include "sml_octet_string.h" #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *codepage; // optional octet_string *client_id; octet_string *req_file_id; octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional u8 *sml_version; // optional } sml_open_request; sml_open_request *sml_open_request_init(); sml_open_request *sml_open_request_parse(sml_buffer *buf); void sml_open_request_write(sml_open_request *msg, sml_buffer *buf); void sml_open_request_free(sml_open_request *msg); #ifdef __cplusplus } #endif #endif /* SML_OPEN_REQUEST_H_ */ sml/include/sml/sml_open_response.h000066400000000000000000000026601455045705600200110ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_OPEN_RESPONSE_H_ #define SML_OPEN_RESPONSE_H_ #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_time.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *codepage; // optional octet_string *client_id; // optional octet_string *req_file_id; octet_string *server_id; sml_time *ref_time; // optional u8 *sml_version; // optional } sml_open_response; sml_open_response *sml_open_response_init(); sml_open_response *sml_open_response_parse(sml_buffer *buf); void sml_open_response_write(sml_open_response *msg, sml_buffer *buf); void sml_open_response_free(sml_open_response *msg); #ifdef __cplusplus } #endif #endif /* SML_OPEN_RESPONSE_H_ */ sml/include/sml/sml_set_proc_parameter_request.h000066400000000000000000000030721455045705600225560ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_SET_PROC_PARAMETER_REQUEST_H_ #define SML_SET_PROC_PARAMETER_REQUEST_H_ #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_tree.h" #ifdef __cplusplus extern "C" { #endif typedef struct { octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional sml_tree_path *parameter_tree_path; sml_tree *parameter_tree; } sml_set_proc_parameter_request; sml_set_proc_parameter_request *sml_set_proc_parameter_request_init(); sml_set_proc_parameter_request *sml_set_proc_parameter_request_parse(sml_buffer *buf); void sml_set_proc_parameter_request_write(sml_set_proc_parameter_request *msg, sml_buffer *buf); void sml_set_proc_parameter_request_free(sml_set_proc_parameter_request *msg); #ifdef __cplusplus } #endif #endif /* SML_SET_PROC_PARAMETER_REQUEST_H_ */ sml/include/sml/sml_shared.h000066400000000000000000000066341455045705600164050ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_SHARED_H_ #define SML_SHARED_H_ #include #include #include #ifdef __cplusplus extern "C" { #endif typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef int8_t i8; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; #define SML_MESSAGE_END 0x0 #define SML_TYPE_FIELD 0x70 #define SML_LENGTH_FIELD 0xF #define SML_ANOTHER_TL 0x80 #define SML_TYPE_OCTET_STRING 0x0 #define SML_TYPE_BOOLEAN 0x40 #define SML_TYPE_INTEGER 0x50 #define SML_TYPE_UNSIGNED 0x60 #define SML_TYPE_LIST 0x70 #define SML_OPTIONAL_SKIPPED 0x1 #define SML_TYPE_NUMBER_8 sizeof(u8) #define SML_TYPE_NUMBER_16 sizeof(u16) #define SML_TYPE_NUMBER_32 sizeof(u32) #define SML_TYPE_NUMBER_64 sizeof(u64) // This sml_buffer is used in two different use-cases. // // Parsing: the raw data is in the buffer field, // the buffer_len is the number of raw bytes received, // the cursor points to the current position during parsing // // Writing: At the beginning the buffer field is malloced and zeroed with // a default length, this default length is stored in buffer_len // (i.e. the maximum bytes one can write to this buffer) // cursor points to the position, where on can write during the // writing process. If a file is completely written to the buffer, // cursor is the number of bytes written to the buffer. typedef struct { unsigned char *buffer; size_t buffer_len; size_t cursor; int error; char *error_msg; } sml_buffer; sml_buffer *sml_buffer_init(size_t length); void sml_buffer_free(sml_buffer *buf); // Returns the length of the following data structure. Sets the cursor position to // the value field. int sml_buf_get_next_length(sml_buffer *buf); void sml_buf_set_type_and_length(sml_buffer *buf, unsigned int type, unsigned int l); // Checks if a error is occured. int sml_buf_has_errors(sml_buffer *buf); // Returns the type field of the current byte. int sml_buf_get_next_type(sml_buffer *buf); // Returns the current byte. unsigned char sml_buf_get_current_byte(sml_buffer *buf); // Returns a pointer to the current buffer position. unsigned char *sml_buf_get_current_buf(sml_buffer *buf); void sml_buf_optional_write(sml_buffer *buf); // Sets the number of bytes read (moves the cursor forward) void sml_buf_update_bytes_read(sml_buffer *buf, int bytes); // Checks if the next field is a skipped optional field, updates the buffer accordingly int sml_buf_optional_is_skipped(sml_buffer *buf); // Prints arbitrarily byte string to stdout with printf void sml_hexdump(unsigned char *buffer, size_t buffer_len); #ifdef __cplusplus } #endif #endif /* SML_SHARED_H_ */ sml/include/sml/sml_status.h000066400000000000000000000023401455045705600164500ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_STATUS_H_ #define SML_STATUS_H_ #include "sml_number.h" #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif typedef struct { u8 type; union { u8 *status8; u16 *status16; u32 *status32; u64 *status64; } data; } sml_status; sml_status *sml_status_init(); sml_status *sml_status_parse(sml_buffer *buf); void sml_status_write(sml_status *status, sml_buffer *buf); void sml_status_free(sml_status *status); #ifdef __cplusplus } #endif #endif /* SML_STATUS_H_ */ sml/include/sml/sml_time.h000066400000000000000000000023461455045705600160710ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_TIME_H_ #define SML_TIME_H_ #include "sml_number.h" #include "sml_shared.h" #ifdef __cplusplus extern "C" { #endif #define SML_TIME_SEC_INDEX 0x01 #define SML_TIME_TIMESTAMP 0x02 typedef struct { u8 *tag; union { u32 *sec_index; u32 *timestamp; } data; } sml_time; sml_time *sml_time_init(); sml_time *sml_time_parse(sml_buffer *buf); void sml_time_write(sml_time *time, sml_buffer *buf); void sml_time_free(sml_time *time); #ifdef __cplusplus } #endif #endif /* SML_TIME_H_ */ sml/include/sml/sml_transport.h000066400000000000000000000035371455045705600171720ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_TRANSPORT_H_ #define SML_TRANSPORT_H_ #include #include #ifdef __cplusplus extern "C" { #endif // sml_transport_read reads continously bytes from fd and scans // for the SML transport protocol escape sequences. If a SML file // is detected it will be copied into the buffer. The total amount of bytes read // will be returned. If the SML file exceeds the len of the buffer, -1 will be returned size_t sml_transport_read(int fd, unsigned char *buffer, size_t max_len); // sml_transport_listen is an endless loop which reads continously // via sml_transport_read and calls the sml_transporter_receiver void sml_transport_listen(int fd, void (*sml_transport_receiver)(unsigned char *buffer, size_t buffer_len)); // sml_transport_writes adds the SML transport protocol escape // sequences and writes the given file to fd. The file must be // in the parsed format. // The number of bytes written is returned, 0 if there was an // error. // The sml_file must be free'd elsewhere. int sml_transport_write(int fd, sml_file *file); #ifdef __cplusplus } #endif #endif /* SML_TRANSPORT_H_ */ sml/include/sml/sml_tree.h000066400000000000000000000070601455045705600160700ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_TREE_H_ #define SML_TREE_H_ #include "sml_octet_string.h" #include "sml_shared.h" #include "sml_time.h" #include "sml_value.h" #ifdef __cplusplus extern "C" { #endif // clang-format off #define SML_PROC_PAR_VALUE_TAG_VALUE 0x01 #define SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY 0x02 #define SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY 0x03 #define SML_PROC_PAR_VALUE_TAG_TIME 0x04 // clang-format on // what a messy tupel ... typedef struct { octet_string *server_id; sml_time *sec_index; u64 *status; sml_unit *unit_pA; i8 *scaler_pA; i64 *value_pA; sml_unit *unit_R1; i8 *scaler_R1; i64 *value_R1; sml_unit *unit_R4; i8 *scaler_R4; i64 *value_R4; octet_string *signature_pA_R1_R4; sml_unit *unit_mA; i8 *scaler_mA; i64 *value_mA; sml_unit *unit_R2; i8 *scaler_R2; i64 *value_R2; sml_unit *unit_R3; i8 *scaler_R3; i64 *value_R3; octet_string *signature_mA_R2_R3; } sml_tupel_entry; typedef struct { octet_string *obj_name; sml_unit *unit; i8 *scaler; sml_value *value; octet_string *value_signature; } sml_period_entry; typedef struct { u8 *tag; union { sml_value *value; sml_period_entry *period_entry; sml_tupel_entry *tupel_entry; sml_time *time; } data; } sml_proc_par_value; typedef struct s_tree { octet_string *parameter_name; sml_proc_par_value *parameter_value; // optional struct s_tree **child_list; // optional int child_list_len; } sml_tree; typedef struct { int path_entries_len; octet_string **path_entries; } sml_tree_path; // sml_tree; sml_tree *sml_tree_init(); sml_tree *sml_tree_parse(sml_buffer *buf); void sml_tree_add_tree(sml_tree *base_tree, sml_tree *tree); void sml_tree_write(sml_tree *tree, sml_buffer *buf); void sml_tree_free(sml_tree *tree); // sml_tree_path; sml_tree_path *sml_tree_path_init(); sml_tree_path *sml_tree_path_parse(sml_buffer *buf); void sml_tree_path_add_path_entry(sml_tree_path *tree_path, octet_string *entry); void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf); void sml_tree_path_free(sml_tree_path *tree_path); // sml_proc_par_value; sml_proc_par_value *sml_proc_par_value_init(); sml_proc_par_value *sml_proc_par_value_parse(sml_buffer *buf); void sml_proc_par_value_write(sml_proc_par_value *value, sml_buffer *buf); void sml_proc_par_value_free(sml_proc_par_value *value); // sml_tupel_entry; sml_tupel_entry *sml_tupel_entry_init(); sml_tupel_entry *sml_tupel_entry_parse(sml_buffer *buf); void sml_tupel_entry_write(sml_tupel_entry *tupel, sml_buffer *buf); void sml_tupel_entry_free(sml_tupel_entry *tupel); // sml_period_entry; sml_period_entry *sml_period_entry_init(); sml_period_entry *sml_period_entry_parse(sml_buffer *buf); void sml_period_entry_write(sml_period_entry *period, sml_buffer *buf); void sml_period_entry_free(sml_period_entry *period); #ifdef __cplusplus } #endif #endif /* SML_TREE_H_ */ sml/include/sml/sml_value.h000066400000000000000000000031551455045705600162460ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef SML_VALUE_H_ #define SML_VALUE_H_ #include "sml_boolean.h" #include "sml_number.h" #include "sml_octet_string.h" #include "sml_shared.h" #include #ifdef __cplusplus extern "C" { #endif typedef struct { u8 type; union { sml_boolean *boolean; octet_string *bytes; // can have zero length i8 *int8; i16 *int16; i32 *int32; i64 *int64; u8 *uint8; u16 *uint16; u32 *uint32; u64 *uint64; } data; } sml_value; sml_value *sml_value_init(); sml_value *sml_value_parse(sml_buffer *buf); void sml_value_write(sml_value *value, sml_buffer *buf); void sml_value_free(sml_value *value); // Cast arbitrary sized sml_value to double double sml_value_to_double(sml_value *value); // Converts SML octet string to a printable hex string char *sml_value_to_strhex(sml_value *value, char **result, bool mixed); #ifdef __cplusplus } #endif #endif /* SML_VALUE_H_ */ sml/lib/000077500000000000000000000000001455045705600124325ustar00rootroot00000000000000sml/lib/.gitdir000066400000000000000000000000001455045705600137030ustar00rootroot00000000000000sml/src/000077500000000000000000000000001455045705600124535ustar00rootroot00000000000000sml/src/sml_attention_response.c000066400000000000000000000047251455045705600174250ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include sml_attention_response *sml_attention_response_init() { sml_attention_response *msg = (sml_attention_response *)malloc(sizeof(sml_attention_response)); *msg = (sml_attention_response){.server_id = NULL, .attention_number = NULL, .attention_message = NULL, .attention_details = NULL}; return msg; } sml_attention_response *sml_attention_response_parse(sml_buffer *buf) { sml_attention_response *msg = sml_attention_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 4) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->attention_number = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->attention_message = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->attention_details = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_attention_response_free(msg); return NULL; } void sml_attention_response_write(sml_attention_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 4); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->attention_number, buf); sml_octet_string_write(msg->attention_message, buf); sml_tree_write(msg->attention_details, buf); } void sml_attention_response_free(sml_attention_response *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->attention_number); sml_octet_string_free(msg->attention_message); sml_tree_free(msg->attention_details); free(msg); } } sml/src/sml_boolean.c000066400000000000000000000036021455045705600151120ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include sml_boolean *sml_boolean_init(u8 b) { sml_boolean *boolean = malloc(sizeof(u8)); *boolean = b; return boolean; } sml_boolean *sml_boolean_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } if (sml_buf_get_next_type(buf) != SML_TYPE_BOOLEAN) { buf->error = 1; return NULL; } int l = sml_buf_get_next_length(buf); if (l != 1) { buf->error = 1; return NULL; } if (buf->cursor >= buf->buffer_len) { buf->error = 1; return NULL; } if (sml_buf_get_current_byte(buf)) { sml_buf_update_bytes_read(buf, 1); return sml_boolean_init(SML_BOOLEAN_TRUE); } else { sml_buf_update_bytes_read(buf, 1); return sml_boolean_init(SML_BOOLEAN_FALSE); } } void sml_boolean_write(sml_boolean *boolean, sml_buffer *buf) { if (boolean == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_BOOLEAN, 1); if (*boolean == SML_BOOLEAN_FALSE) { buf->buffer[buf->cursor] = SML_BOOLEAN_FALSE; } else { buf->buffer[buf->cursor] = SML_BOOLEAN_TRUE; } buf->cursor++; } void sml_boolean_free(sml_boolean *b) { if (b) { free(b); } } sml/src/sml_close_request.c000066400000000000000000000034051455045705600163510ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include sml_close_request *sml_close_request_init() { sml_close_request *close_request = (sml_close_request *)malloc(sizeof(sml_close_request)); *close_request = (sml_close_request){.global_signature = NULL}; return close_request; } sml_close_request *sml_close_request_parse(sml_buffer *buf) { sml_close_request *msg = sml_close_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 1) { buf->error = 1; goto error; } msg->global_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_close_request_free(msg); return NULL; } void sml_close_request_write(sml_close_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 1); sml_octet_string_write(msg->global_signature, buf); } void sml_close_request_free(sml_close_request *msg) { if (msg) { sml_octet_string_free(msg->global_signature); free(msg); } } sml/src/sml_close_response.c000066400000000000000000000033701455045705600165200ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include sml_close_response *sml_close_response_init() { sml_close_response *msg = (sml_close_response *)malloc(sizeof(sml_close_response)); *msg = (sml_close_response){.global_signature = NULL}; return msg; } sml_close_response *sml_close_response_parse(sml_buffer *buf) { sml_close_response *msg = sml_close_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 1) { buf->error = 1; goto error; } msg->global_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_close_response_free(msg); return NULL; } void sml_close_response_write(sml_close_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 1); sml_octet_string_write(msg->global_signature, buf); } void sml_close_response_free(sml_close_response *msg) { if (msg) { sml_octet_string_free(msg->global_signature); free(msg); } } sml/src/sml_crc16.c000066400000000000000000000064471455045705600144230ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #define PPPINITFCS16 0xffff // initial FCS value // table taken from DIN EN 62056-46 static u16 crctab[256] = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78}; u16 sml_crc16_calculate(unsigned char *cp, int len) { u16 fcs = PPPINITFCS16; while (len--) { fcs = (fcs >> 8) ^ crctab[(fcs ^ *cp++) & 0xff]; } fcs ^= 0xffff; fcs = ((fcs & 0xff) << 8) | ((fcs & 0xff00) >> 8); return fcs; } u16 sml_crc16kermit_calculate(unsigned char *cp, int len) { u16 crc = 0x000; while (len--) { crc = (crc >> 8) ^ crctab[(crc ^ *cp++) & 0xff]; } return crc; } sml/src/sml_file.c000066400000000000000000000057361455045705600144240ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include #include #include #include #include // EDL meter must provide at least 250 bytes as a receive buffer #define SML_FILE_BUFFER_LENGTH 512 sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len) { sml_file *file = (sml_file *)malloc(sizeof(sml_file)); *file = (sml_file){.messages = NULL, .messages_len = 0, .buf = NULL}; sml_buffer *buf = sml_buffer_init(buffer_len); memcpy(buf->buffer, buffer, buffer_len); file->buf = buf; sml_message *msg; // parsing all messages for (; buf->cursor < buf->buffer_len;) { if (sml_buf_get_current_byte(buf) == SML_MESSAGE_END) { // reading trailing zeroed bytes sml_buf_update_bytes_read(buf, 1); continue; } msg = sml_message_parse(buf); if (sml_buf_has_errors(buf)) { fprintf(stderr, "libsml: warning: could not read the whole file\n"); break; } if (msg) sml_file_add_message(file, msg); } return file; } sml_file *sml_file_init() { sml_file *file = (sml_file *)malloc(sizeof(sml_file)); *file = (sml_file){.messages = NULL, .messages_len = 0, .buf = NULL}; sml_buffer *buf = sml_buffer_init(SML_FILE_BUFFER_LENGTH); file->buf = buf; return file; } void sml_file_add_message(sml_file *file, sml_message *message) { file->messages_len++; file->messages = (sml_message **)realloc(file->messages, sizeof(sml_message *) * file->messages_len); file->messages[file->messages_len - 1] = message; } void sml_file_write(sml_file *file) { int i; if (file->messages && file->messages_len > 0) { for (i = 0; i < file->messages_len; i++) { sml_message_write(file->messages[i], file->buf); } } } void sml_file_free(sml_file *file) { if (file) { if (file->messages) { int i; for (i = 0; i < file->messages_len; i++) { sml_message_free(file->messages[i]); } free(file->messages); } if (file->buf) { sml_buffer_free(file->buf); } free(file); } } void sml_file_print(sml_file *file) { int i; printf("SML file (%d SML messages, %zu bytes)\n", file->messages_len, file->buf->cursor); for (i = 0; i < file->messages_len; i++) { printf("SML message %4.X\n", *(file->messages[i]->message_body->tag)); } } sml/src/sml_get_list_request.c000066400000000000000000000053721455045705600170630ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include sml_get_list_request *sml_get_list_request_init() { sml_get_list_request *msg = (sml_get_list_request *)malloc(sizeof(sml_get_list_request)); *msg = (sml_get_list_request){.client_id = NULL, .server_id = NULL, .username = NULL, .password = NULL, .list_name = NULL}; return msg; } void sml_get_list_request_write(sml_get_list_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); sml_octet_string_write(msg->client_id, buf); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username, buf); sml_octet_string_write(msg->password, buf); sml_octet_string_write(msg->list_name, buf); } sml_get_list_request *sml_get_list_request_parse(sml_buffer *buf) { sml_get_list_request *msg = (sml_get_list_request *)malloc(sizeof(sml_get_list_request)); *msg = (sml_get_list_request){.client_id = NULL, .server_id = NULL, .username = NULL, .password = NULL, .list_name = NULL}; if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 5) { buf->error = 1; goto error; } msg->client_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->list_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_list_request_free(msg); return NULL; } void sml_get_list_request_free(sml_get_list_request *msg) { if (msg) { sml_octet_string_free(msg->client_id); sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->list_name); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); free(msg); } } sml/src/sml_get_list_response.c000066400000000000000000000057341455045705600172330ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include sml_get_list_response *sml_get_list_response_init() { sml_get_list_response *msg = (sml_get_list_response *)malloc(sizeof(sml_get_list_response)); *msg = (sml_get_list_response){.client_id = NULL, .server_id = NULL, .list_name = NULL, .act_sensor_time = NULL, .val_list = NULL, .list_signature = NULL, .act_gateway_time = NULL}; return msg; } sml_get_list_response *sml_get_list_response_parse(sml_buffer *buf) { sml_get_list_response *msg = sml_get_list_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 7) { buf->error = 1; goto error; } msg->client_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->list_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->act_sensor_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->val_list = sml_list_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->list_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->act_gateway_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_list_response_free(msg); return NULL; } void sml_get_list_response_write(sml_get_list_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7); sml_octet_string_write(msg->client_id, buf); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->list_name, buf); sml_time_write(msg->act_sensor_time, buf); sml_list_write(msg->val_list, buf); sml_octet_string_write(msg->list_signature, buf); sml_time_write(msg->act_gateway_time, buf); } void sml_get_list_response_free(sml_get_list_response *msg) { if (msg) { sml_octet_string_free(msg->client_id); sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->list_name); sml_time_free(msg->act_sensor_time); sml_list_free(msg->val_list); sml_octet_string_free(msg->list_signature); sml_time_free(msg->act_gateway_time); free(msg); } } sml/src/sml_get_proc_parameter_request.c000066400000000000000000000054241455045705600211110ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include sml_get_proc_parameter_request *sml_get_proc_parameter_request_init() { sml_get_proc_parameter_request *msg = (sml_get_proc_parameter_request *)malloc(sizeof(sml_get_proc_parameter_request)); *msg = (sml_get_proc_parameter_request){.server_id = NULL, .username = NULL, .password = NULL, .parameter_tree_path = NULL, .attribute = NULL}; return msg; } sml_get_proc_parameter_request *sml_get_proc_parameter_request_parse(sml_buffer *buf) { sml_get_proc_parameter_request *msg = sml_get_proc_parameter_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 5) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->attribute = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_proc_parameter_request_free(msg); return NULL; } void sml_get_proc_parameter_request_write(sml_get_proc_parameter_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username, buf); sml_octet_string_write(msg->password, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_octet_string_write(msg->attribute, buf); } void sml_get_proc_parameter_request_free(sml_get_proc_parameter_request *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); sml_tree_path_free(msg->parameter_tree_path); sml_octet_string_free(msg->attribute); free(msg); } } sml/src/sml_get_proc_parameter_response.c000066400000000000000000000045301455045705600212540ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include sml_get_proc_parameter_response *sml_get_proc_parameter_response_init() { sml_get_proc_parameter_response *msg = (sml_get_proc_parameter_response *)malloc(sizeof(sml_get_proc_parameter_response)); *msg = (sml_get_proc_parameter_response){ .server_id = NULL, .parameter_tree_path = NULL, .parameter_tree = NULL}; return msg; } sml_get_proc_parameter_response *sml_get_proc_parameter_response_parse(sml_buffer *buf) { sml_get_proc_parameter_response *msg = sml_get_proc_parameter_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 3) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_proc_parameter_response_free(msg); return NULL; } void sml_get_proc_parameter_response_write(sml_get_proc_parameter_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3); sml_octet_string_write(msg->server_id, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_tree_write(msg->parameter_tree, buf); } void sml_get_proc_parameter_response_free(sml_get_proc_parameter_response *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_tree_path_free(msg->parameter_tree_path); sml_tree_free(msg->parameter_tree); free(msg); } } sml/src/sml_get_profile_list_request.c000066400000000000000000000015631455045705600206010ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include // this file is just there for symmetry void sml_get_profile_list_request_noop() {} sml/src/sml_get_profile_list_response.c000066400000000000000000000075241455045705600207520ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include // sml_get_profile_list_response; sml_get_profile_list_response *sml_get_profile_list_response_init() { sml_get_profile_list_response *msg = (sml_get_profile_list_response *)malloc(sizeof(sml_get_profile_list_response)); *msg = (sml_get_profile_list_response){.server_id = NULL, .act_time = NULL, .reg_period = NULL, .parameter_tree_path = NULL, .val_time = NULL, .status = NULL, .period_list = NULL, .rawdata = NULL, .period_signature = NULL}; return msg; } static void *sml_period_entry_parse_(sml_buffer *buf) { return sml_period_entry_parse(buf); } static void sml_period_entry_free_(void *p) { sml_period_entry_free(p); } sml_get_profile_list_response *sml_get_profile_list_response_parse(sml_buffer *buf) { sml_get_profile_list_response *msg = sml_get_profile_list_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 9) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->act_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->reg_period = sml_u32_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->val_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->status = sml_u64_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->period_list = sml_sequence_parse(buf, sml_period_entry_parse_, sml_period_entry_free_); if (sml_buf_has_errors(buf)) goto error; msg->rawdata = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->period_signature = sml_signature_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: buf->error = 1; sml_get_profile_list_response_free(msg); return NULL; } static void sml_period_entry_write_(void *p, sml_buffer *buf) { sml_period_entry_write(p, buf); } void sml_get_profile_list_response_write(sml_get_profile_list_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9); sml_octet_string_write(msg->server_id, buf); sml_time_write(msg->act_time, buf); sml_u32_write(msg->reg_period, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_time_write(msg->val_time, buf); sml_u64_write(msg->status, buf); sml_sequence_write(msg->period_list, buf, sml_period_entry_write_); sml_octet_string_write(msg->rawdata, buf); sml_signature_write(msg->period_signature, buf); } void sml_get_profile_list_response_free(sml_get_profile_list_response *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_time_free(msg->act_time); sml_number_free(msg->reg_period); sml_tree_path_free(msg->parameter_tree_path); sml_time_free(msg->val_time); sml_number_free(msg->status); sml_sequence_free(msg->period_list); sml_octet_string_free(msg->rawdata); sml_signature_free(msg->period_signature); free(msg); } } sml/src/sml_get_profile_pack_request.c000066400000000000000000000112561455045705600205440ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include #include #include sml_get_profile_pack_request *sml_get_profile_pack_request_init() { sml_get_profile_pack_request *msg = (sml_get_profile_pack_request *)malloc(sizeof(sml_get_profile_pack_request)); *msg = (sml_get_profile_pack_request){.server_id = NULL, .username = NULL, .password = NULL, .with_rawdata = NULL, .begin_time = NULL, .end_time = NULL, .parameter_tree_path = NULL, .object_list = NULL, .das_details = NULL}; return msg; } void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username, buf); sml_octet_string_write(msg->password, buf); sml_boolean_write(msg->with_rawdata, buf); sml_time_write(msg->begin_time, buf); sml_time_write(msg->end_time, buf); sml_tree_path_write(msg->parameter_tree_path, buf); if (msg->object_list) { int len = 1; sml_obj_req_entry_list *l = msg->object_list; for (l = msg->object_list; l->next; l = l->next) { len++; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, len); for (l = msg->object_list; l->next; l = l->next) { sml_obj_req_entry_write(l->object_list_entry, buf); } } else { sml_buf_optional_write(buf); } sml_tree_write(msg->das_details, buf); } sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf) { sml_get_profile_pack_request *msg = sml_get_profile_pack_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 9) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->with_rawdata = sml_boolean_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->begin_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->end_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (!sml_buf_optional_is_skipped(buf)) { if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } int i, len = sml_buf_get_next_length(buf); sml_obj_req_entry_list *last = 0, *n = 0; for (i = len; i > 0; i--) { n = (sml_obj_req_entry_list *)malloc(sizeof(sml_obj_req_entry_list)); *n = (sml_obj_req_entry_list){.object_list_entry = NULL, .next = NULL}; n->object_list_entry = sml_obj_req_entry_parse(buf); if (sml_buf_has_errors(buf)) { if (n->object_list_entry) sml_octet_string_free(n->object_list_entry); free(n); goto error; } if (msg->object_list == 0) { msg->object_list = n; last = msg->object_list; } else { last->next = n; last = n; } } } msg->das_details = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_get_profile_pack_request_free(msg); return NULL; } void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); sml_boolean_free(msg->with_rawdata); sml_time_free(msg->begin_time); sml_time_free(msg->end_time); sml_tree_path_free(msg->parameter_tree_path); if (msg->object_list) { sml_obj_req_entry_list *n = 0, *d = msg->object_list; do { n = d->next; sml_obj_req_entry_free(d->object_list_entry); free(d); d = n; } while (d); } sml_tree_free(msg->das_details); free(msg); } } sml/src/sml_get_profile_pack_response.c000066400000000000000000000223051455045705600207070ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include static void *sml_prof_obj_header_entry_parse_(sml_buffer *buf); static void *sml_value_entry_parse_(sml_buffer *buf); static void sml_value_entry_free_(void *p); static void sml_value_entry_write_(void *p, sml_buffer *buf); static void sml_prof_obj_header_entry_free_(void *p) { sml_prof_obj_header_entry *entry = p; if (entry) { sml_octet_string_free(entry->obj_name); sml_unit_free(entry->unit); sml_number_free(entry->scaler); free(entry); } } static void *sml_prof_obj_period_entry_parse_(sml_buffer *buf) { sml_prof_obj_period_entry *entry = sml_prof_obj_period_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 4) { buf->error = 1; goto error; } entry->val_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->status = sml_u64_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->value_list = sml_sequence_parse(buf, sml_value_entry_parse_, sml_value_entry_free_); if (sml_buf_has_errors(buf)) goto error; entry->period_signature = sml_signature_parse(buf); if (sml_buf_has_errors(buf)) goto error; return entry; error: buf->error = 1; sml_prof_obj_period_entry_free(entry); return NULL; } static void sml_prof_obj_period_entry_free_(void *p) { sml_prof_obj_period_entry *entry = p; if (entry) { sml_time_free(entry->val_time); sml_number_free(entry->status); sml_sequence_free(entry->value_list); sml_signature_free(entry->period_signature); free(entry); } } static void sml_prof_obj_header_entry_write_(void *p, sml_buffer *buf) { sml_prof_obj_header_entry *entry = p; sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3); sml_octet_string_write(entry->obj_name, buf); sml_unit_write(entry->unit, buf); sml_i8_write(entry->scaler, buf); } static void sml_prof_obj_period_entry_write_(void *p, sml_buffer *buf) { sml_prof_obj_period_entry *entry = p; sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 4); sml_time_write(entry->val_time, buf); sml_u64_write(entry->status, buf); sml_sequence_write(entry->value_list, buf, sml_value_entry_write_); sml_signature_write(entry->period_signature, buf); } static void *sml_value_entry_parse_(sml_buffer *buf) { sml_value_entry *entry = sml_value_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 2) { buf->error = 1; goto error; } entry->value = sml_value_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->value_signature = sml_signature_parse(buf); if (sml_buf_has_errors(buf)) goto error; return entry; error: buf->error = 1; sml_value_entry_free(entry); return NULL; } static void sml_value_entry_write_(void *p, sml_buffer *buf) { sml_value_entry *entry = p; sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); sml_value_write(entry->value, buf); sml_signature_write(entry->value_signature, buf); } static void sml_value_entry_free_(void *p) { sml_value_entry *entry = p; if (entry) { sml_value_free(entry->value); sml_signature_free(entry->value_signature); free(entry); } } // sml_get_profile_pack_response; sml_get_profile_pack_response *sml_get_profile_pack_response_init() { sml_get_profile_pack_response *msg = (sml_get_profile_pack_response *)malloc(sizeof(sml_get_profile_pack_response)); *msg = (sml_get_profile_pack_response){.server_id = NULL, .act_time = NULL, .reg_period = NULL, .parameter_tree_path = NULL, .header_list = NULL, .period_list = NULL, .rawdata = NULL, .profile_signature = NULL}; return msg; } sml_get_profile_pack_response *sml_get_profile_pack_response_parse(sml_buffer *buf) { sml_get_profile_pack_response *msg = sml_get_profile_pack_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 8) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->act_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->reg_period = sml_u32_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->header_list = sml_sequence_parse(buf, sml_prof_obj_header_entry_parse_, sml_prof_obj_header_entry_free_); if (sml_buf_has_errors(buf)) goto error; msg->period_list = sml_sequence_parse(buf, sml_prof_obj_period_entry_parse_, sml_prof_obj_period_entry_free_); if (sml_buf_has_errors(buf)) goto error; msg->rawdata = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->profile_signature = sml_signature_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: buf->error = 1; sml_get_profile_pack_response_free(msg); return NULL; } void sml_get_profile_pack_response_write(sml_get_profile_pack_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 8); sml_octet_string_write(msg->server_id, buf); sml_time_write(msg->act_time, buf); sml_u32_write(msg->reg_period, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_sequence_write(msg->header_list, buf, sml_prof_obj_header_entry_write_); sml_sequence_write(msg->period_list, buf, sml_prof_obj_period_entry_write_); sml_octet_string_write(msg->rawdata, buf); sml_signature_write(msg->profile_signature, buf); } void sml_get_profile_pack_response_free(sml_get_profile_pack_response *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_time_free(msg->act_time); sml_number_free(msg->reg_period); sml_tree_path_free(msg->parameter_tree_path); sml_sequence_free(msg->header_list); sml_sequence_free(msg->period_list); sml_octet_string_free(msg->rawdata); sml_signature_free(msg->profile_signature); free(msg); } } // sml_prof_obj_header_entry; sml_prof_obj_header_entry *sml_prof_obj_header_entry_init() { sml_prof_obj_header_entry *entry = (sml_prof_obj_header_entry *)malloc(sizeof(sml_prof_obj_header_entry)); *entry = (sml_prof_obj_header_entry){.obj_name = NULL, .unit = NULL, .scaler = NULL}; return entry; } static void *sml_prof_obj_header_entry_parse_(sml_buffer *buf) { sml_prof_obj_header_entry *entry = sml_prof_obj_header_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 3) { buf->error = 1; goto error; } entry->obj_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->unit = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; entry->scaler = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; return entry; error: buf->error = 1; sml_prof_obj_header_entry_free(entry); return NULL; } sml_prof_obj_header_entry *sml_prof_obj_header_entry_parse(sml_buffer *buf) { return sml_prof_obj_header_entry_parse_(buf); } void sml_prof_obj_header_entry_write(sml_prof_obj_header_entry *entry, sml_buffer *buf) { sml_prof_obj_header_entry_write_(entry, buf); } void sml_prof_obj_header_entry_free(sml_prof_obj_header_entry *entry) { sml_prof_obj_header_entry_free_(entry); } // sml_prof_obj_period_entry; sml_prof_obj_period_entry *sml_prof_obj_period_entry_init() { sml_prof_obj_period_entry *entry = (sml_prof_obj_period_entry *)malloc(sizeof(sml_prof_obj_period_entry)); *entry = (sml_prof_obj_period_entry){ .val_time = NULL, .status = NULL, .value_list = NULL, .period_signature = NULL}; return entry; } sml_prof_obj_period_entry *sml_prof_obj_period_entry_parse(sml_buffer *buf) { return sml_prof_obj_period_entry_parse_(buf); } void sml_prof_obj_period_entry_write(sml_prof_obj_period_entry *entry, sml_buffer *buf) { sml_prof_obj_period_entry_write_(entry, buf); } void sml_prof_obj_period_entry_free(sml_prof_obj_period_entry *entry) { sml_prof_obj_period_entry_free_(entry); } // sml_value_entry; sml_value_entry *sml_value_entry_init() { sml_value_entry *entry = (sml_value_entry *)malloc(sizeof(sml_value_entry)); *entry = (sml_value_entry){.value = NULL, .value_signature = NULL}; return entry; } sml_value_entry *sml_value_entry_parse(sml_buffer *buf) { return sml_value_entry_parse_(buf); } void sml_value_entry_write(sml_value_entry *entry, sml_buffer *buf) { sml_value_entry_write_(entry, buf); } void sml_value_entry_free(sml_value_entry *entry) { sml_value_entry_free_(entry); } sml/src/sml_list.c000066400000000000000000000217351455045705600144550ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include #include #include #include #include // sml_sequence; sml_sequence *sml_sequence_init(void (*elem_free)(void *elem)) { sml_sequence *seq = (sml_sequence *)malloc(sizeof(sml_sequence)); *seq = (sml_sequence){.elems = NULL, .elems_len = 0, .elem_free = elem_free}; return seq; } sml_sequence *sml_sequence_parse(sml_buffer *buf, void *(*elem_parse)(sml_buffer *buf), void (*elem_free)(void *elem)) { if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { goto error; } sml_sequence *seq = sml_sequence_init(elem_free); int i, len = sml_buf_get_next_length(buf); void *p; for (i = 0; i < len; i++) { p = elem_parse(buf); if (sml_buf_has_errors(buf)) { goto haserrors; } sml_sequence_add(seq, p); } return seq; haserrors: sml_sequence_free(seq); error: buf->error = 1; return NULL; } void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write)(void *elem, sml_buffer *buf)) { if (seq == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, seq->elems_len); int i; for (i = 0; i < seq->elems_len; i++) { elem_write((seq->elems)[i], buf); } } void sml_sequence_free(sml_sequence *seq) { if (seq) { int i; for (i = 0; i < seq->elems_len; i++) { seq->elem_free((seq->elems)[i]); } if (seq->elems != 0) { free(seq->elems); } free(seq); } } void sml_sequence_add(sml_sequence *seq, void *new_entry) { seq->elems_len++; seq->elems = (void **)realloc(seq->elems, sizeof(void *) * seq->elems_len); seq->elems[seq->elems_len - 1] = new_entry; } // sml_list; sml_list *sml_list_init() { sml_list *s = (sml_list *)malloc(sizeof(sml_list)); *s = (sml_list){.obj_name = NULL, .status = NULL, .val_time = NULL, .unit = NULL, .scaler = NULL, .value = NULL, .value_signature = NULL, .next = NULL}; return s; } void sml_list_add(sml_list *list, sml_list *new_entry) { list->next = new_entry; } /* Note: this gets invoked for _every_ object seen */ static bool detect_buggy_dzg_dvs74(sml_list *l) { #define DZG_SERIAL_LENGTH 10 static const unsigned char dzg_serial_oid[] = {1, 0, 96, 1, 0, 255}; static const unsigned char dzg_serial_start[] = { 0x0a, 0x01, 'D', 'Z', 'G' }; static const struct { uint64_t start, end; } broken_dvs74_ranges[] = { { .start = 42000000, .end = 48999999 }, { .start = 55000000, .end = 58999999 }, }; #define NUM_BROKEN_RANGES (sizeof(broken_dvs74_ranges)/sizeof(broken_dvs74_ranges[0])) const unsigned char *val; uint64_t serial = 0; unsigned int i; /* check that object ID is for the serial number */ if (!l->obj_name || l->obj_name->len != sizeof(dzg_serial_oid) || memcmp(l->obj_name->str, dzg_serial_oid, sizeof(dzg_serial_oid))) return false; /* check that it's an octet string of the right length */ if (!l->value || l->value->type != SML_TYPE_OCTET_STRING || l->value->data.bytes->len != DZG_SERIAL_LENGTH) return false; val = l->value->data.bytes->str; /* check that it's a DZG meter at all */ if (memcmp(val, dzg_serial_start, sizeof(dzg_serial_start))) return false; /* convert remainder of serial number to integer */ for (i = sizeof(dzg_serial_start); i < DZG_SERIAL_LENGTH; i++) { serial <<= 8; serial |= val[i]; } /* * Check that it's in one of the affected ranges, * which means it's a DVS74 with the bug * (DVS74 with serial >= 60000000 have the bug fixed) */ for (i = 0; i < NUM_BROKEN_RANGES; i++) { if (serial >= broken_dvs74_ranges[i].start && serial <= broken_dvs74_ranges[i].end) return true; } return false; } struct workarounds { unsigned int old_dzg_dvs74 : 1; }; sml_list *sml_list_entry_parse(sml_buffer *buf, struct workarounds *workarounds) { static const unsigned char dzg_power_name[] = {1, 0, 16, 7, 0, 255}; u8 value_tl, value_len_more; sml_list *l = NULL; if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 7) { buf->error = 1; goto error; } l = sml_list_init(); l->obj_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->status = sml_status_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->val_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->unit = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->scaler = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (buf->cursor >= buf->buffer_len) { goto error; } value_tl = sml_buf_get_current_byte(buf); value_len_more = value_tl & (SML_ANOTHER_TL | SML_LENGTH_FIELD); l->value = sml_value_parse(buf); if (sml_buf_has_errors(buf)) goto error; l->value_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; /* * Work around DZG DVS74 meters in the serial number ranges listed * in detect_buggy_dzg_dvs74() above - they encode the consumption * incorrectly: * The value uses a scaler of -2, so e.g. 328.05 should be * encoded as an unsigned int with 2 bytes (called Unsigned16 in the standard): * 63 80 25 (0x8025 == 32805 corresponds to 328.05W) * or as an unsigned int with 3 bytes (not named in the standard): * 64 00 80 25 * or as a signed int with 3 bytes (not named in the standard): * 54 00 80 25 * but they encode it as a signed int with 2 bytes (called Integer16 in the standard): * 53 80 25 * which reads as -32731 corresponding to -327.31W. * * Luckily, it doesn't attempt to do any compression on * negative values, they're always encoded as, e.g. * 55 ff fe 13 93 (== -126061 -> -1260.61W) * * Since we cannot have positive values >= 0x80000000 * (that would be 21474836.48 W, yes, >21MW), we can * assume that for 1, 2, 3 bytes, if they look signed, * they really were intended to be unsigned. * * Note that this will NOT work if a meter outputs negative * values compressed as well - but mine doesn't. */ if (detect_buggy_dzg_dvs74(l)) { workarounds->old_dzg_dvs74 = 1; } else if (workarounds->old_dzg_dvs74 && l->obj_name && l->obj_name->len == sizeof(dzg_power_name) && memcmp(l->obj_name->str, dzg_power_name, sizeof(dzg_power_name)) == 0 && l->value && (value_len_more == 1 || value_len_more == 2 || value_len_more == 3)) { l->value->type &= ~SML_TYPE_FIELD; l->value->type |= SML_TYPE_UNSIGNED; } return l; error: buf->error = 1; if (l) { sml_list_free(l); } return NULL; } sml_list *sml_list_parse(sml_buffer *buf) { struct workarounds workarounds = {0}; sml_list *ret = NULL, **pos = &ret; int elems; if (sml_buf_optional_is_skipped(buf)) { return NULL; } if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; return NULL; } elems = sml_buf_get_next_length(buf); while (elems > 0) { *pos = sml_list_entry_parse(buf, &workarounds); if (sml_buf_has_errors(buf)) goto error; pos = &(*pos)->next; elems--; } return ret; error: buf->error = 1; sml_list_free(ret); return NULL; } void sml_list_entry_write(sml_list *list, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7); sml_octet_string_write(list->obj_name, buf); sml_status_write(list->status, buf); sml_time_write(list->val_time, buf); sml_u8_write(list->unit, buf); sml_i8_write(list->scaler, buf); sml_value_write(list->value, buf); sml_octet_string_write(list->value_signature, buf); } void sml_list_write(sml_list *list, sml_buffer *buf) { if (list == 0) { sml_buf_optional_write(buf); return; } sml_list *i = list; int len = 0; while (i) { i = i->next; len++; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, len); i = list; while (i) { sml_list_entry_write(i, buf); i = i->next; } } void sml_list_entry_free(sml_list *list) { if (list) { sml_octet_string_free(list->obj_name); sml_status_free(list->status); sml_time_free(list->val_time); sml_number_free(list->unit); sml_number_free(list->scaler); sml_value_free(list->value); sml_octet_string_free(list->value_signature); free(list); } } void sml_list_free(sml_list *list) { if (list) { sml_list *f = list; sml_list *n = list->next; while (f) { sml_list_entry_free(f); f = n; if (f) { n = f->next; } } } } sml/src/sml_message.c000066400000000000000000000251451455045705600151250ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include #include #include #include #include #include #include #include // sml_message; sml_message *sml_message_parse(sml_buffer *buf) { sml_message *msg = (sml_message *)malloc(sizeof(sml_message)); *msg = (sml_message){.transaction_id = NULL, .group_id = NULL, .abort_on_error = NULL, .message_body = NULL, .crc = NULL}; int msg_start = buf->cursor; int len; if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 6) { buf->error = 1; goto error; } msg->transaction_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->group_id = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->abort_on_error = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->message_body = sml_message_body_parse(buf); if (sml_buf_has_errors(buf)) goto error; len = buf->cursor - msg_start; if ((buf->buffer_len - buf->cursor) < 3) { // libFuzzer ASAN found read out of bound. // at least the 2 bytes for the crc and 1 for the sml_message_end there? buf->error = 1; goto error; } msg->crc = sml_u16_parse(buf); if (sml_buf_has_errors(buf) || !(msg->crc)) { buf->error = 1; goto error; } if ( *msg->crc != sml_crc16_calculate(&(buf->buffer[msg_start]), len) && // Workaround for Holley DTZ541 uses CRC-16/Kermit *msg->crc != sml_crc16kermit_calculate(&(buf->buffer[msg_start]), len) ){ fprintf(stderr, "libsml: sml_message_parse(): crc mismatch, dropping message\n"); goto error; } if (buf->cursor >= buf->buffer_len) { buf->error = 1; goto error; } if (sml_buf_get_current_byte(buf) == SML_MESSAGE_END) { sml_buf_update_bytes_read(buf, 1); } return msg; error: sml_message_free(msg); return NULL; } sml_message *sml_message_init() { sml_message *msg = (sml_message *)malloc(sizeof(sml_message)); *msg = (sml_message){.transaction_id = NULL, .group_id = NULL, .abort_on_error = NULL, .message_body = NULL, .crc = NULL}; msg->transaction_id = sml_octet_string_generate_uuid(); return msg; } void sml_message_free(sml_message *msg) { if (msg) { sml_octet_string_free(msg->transaction_id); sml_number_free(msg->group_id); sml_number_free(msg->abort_on_error); sml_message_body_free(msg->message_body); sml_number_free(msg->crc); free(msg); } } void sml_message_write(sml_message *msg, sml_buffer *buf) { int msg_start = buf->cursor; sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 6); sml_octet_string_write(msg->transaction_id, buf); sml_u8_write(msg->group_id, buf); sml_u8_write(msg->abort_on_error, buf); sml_message_body_write(msg->message_body, buf); msg->crc = sml_u16_init(sml_crc16_calculate(&(buf->buffer[msg_start]), buf->cursor - msg_start)); sml_u16_write(msg->crc, buf); // end of message buf->buffer[buf->cursor] = 0x0; buf->cursor++; } // sml_message_body; sml_message_body *sml_message_body_parse(sml_buffer *buf) { sml_message_body *msg_body = (sml_message_body *)malloc(sizeof(sml_message_body)); *msg_body = (sml_message_body){.tag = NULL, .data = NULL}; if ((buf->cursor + 1) > buf->buffer_len) { buf->error = 1; goto error; } if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 2) { buf->error = 1; goto error; } msg_body->tag = sml_u32_parse(buf); if (sml_buf_has_errors(buf) || msg_body->tag == NULL) goto error; switch (*(msg_body->tag)) { case SML_MESSAGE_OPEN_REQUEST: msg_body->data = sml_open_request_parse(buf); break; case SML_MESSAGE_OPEN_RESPONSE: msg_body->data = sml_open_response_parse(buf); break; case SML_MESSAGE_CLOSE_REQUEST: msg_body->data = sml_close_request_parse(buf); break; case SML_MESSAGE_CLOSE_RESPONSE: msg_body->data = sml_close_response_parse(buf); break; case SML_MESSAGE_GET_PROFILE_PACK_REQUEST: msg_body->data = sml_get_profile_pack_request_parse(buf); break; case SML_MESSAGE_GET_PROFILE_PACK_RESPONSE: msg_body->data = sml_get_profile_pack_response_parse(buf); break; case SML_MESSAGE_GET_PROFILE_LIST_REQUEST: msg_body->data = sml_get_profile_list_request_parse(buf); break; case SML_MESSAGE_GET_PROFILE_LIST_RESPONSE: msg_body->data = sml_get_profile_list_response_parse(buf); break; case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST: msg_body->data = sml_get_proc_parameter_request_parse(buf); break; case SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE: msg_body->data = sml_get_proc_parameter_response_parse(buf); break; case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST: msg_body->data = sml_set_proc_parameter_request_parse(buf); break; case SML_MESSAGE_GET_LIST_REQUEST: msg_body->data = sml_get_list_request_parse(buf); break; case SML_MESSAGE_GET_LIST_RESPONSE: msg_body->data = sml_get_list_response_parse(buf); break; case SML_MESSAGE_ATTENTION_RESPONSE: msg_body->data = sml_attention_response_parse(buf); break; default: fprintf(stderr, "libsml: error: message type %04X not yet implemented\n", *(msg_body->tag)); break; } return msg_body; error: free(msg_body); return NULL; } sml_message_body *sml_message_body_init(u32 tag, void *data) { sml_message_body *message_body = (sml_message_body *)malloc(sizeof(sml_message_body)); *message_body = (sml_message_body){.tag = sml_u32_init(tag), .data = data}; return message_body; } void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); sml_u32_write(message_body->tag, buf); switch (*(message_body->tag)) { case SML_MESSAGE_OPEN_REQUEST: sml_open_request_write((sml_open_request *)message_body->data, buf); break; case SML_MESSAGE_OPEN_RESPONSE: sml_open_response_write((sml_open_response *)message_body->data, buf); break; case SML_MESSAGE_CLOSE_REQUEST: sml_close_request_write((sml_close_request *)message_body->data, buf); break; case SML_MESSAGE_CLOSE_RESPONSE: sml_close_response_write((sml_close_response *)message_body->data, buf); break; case SML_MESSAGE_GET_PROFILE_PACK_REQUEST: sml_get_profile_pack_request_write((sml_get_profile_pack_request *)message_body->data, buf); break; case SML_MESSAGE_GET_PROFILE_PACK_RESPONSE: sml_get_profile_pack_response_write((sml_get_profile_pack_response *)message_body->data, buf); break; case SML_MESSAGE_GET_PROFILE_LIST_REQUEST: sml_get_profile_list_request_write((sml_get_profile_list_request *)message_body->data, buf); break; case SML_MESSAGE_GET_PROFILE_LIST_RESPONSE: sml_get_profile_list_response_write((sml_get_profile_list_response *)message_body->data, buf); break; case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST: sml_get_proc_parameter_request_write((sml_get_proc_parameter_request *)message_body->data, buf); break; case SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE: sml_get_proc_parameter_response_write((sml_get_proc_parameter_response *)message_body->data, buf); break; case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST: sml_set_proc_parameter_request_write((sml_set_proc_parameter_request *)message_body->data, buf); break; case SML_MESSAGE_GET_LIST_REQUEST: sml_get_list_request_write((sml_get_list_request *)message_body->data, buf); break; case SML_MESSAGE_GET_LIST_RESPONSE: sml_get_list_response_write((sml_get_list_response *)message_body->data, buf); break; case SML_MESSAGE_ATTENTION_RESPONSE: sml_attention_response_write((sml_attention_response *)message_body->data, buf); break; default: fprintf(stderr, "libsml: error: message type %04X not yet implemented\n", *(message_body->tag)); break; } } void sml_message_body_free(sml_message_body *message_body) { if (message_body) { switch (*(message_body->tag)) { case SML_MESSAGE_OPEN_REQUEST: sml_open_request_free((sml_open_request *)message_body->data); break; case SML_MESSAGE_OPEN_RESPONSE: sml_open_response_free((sml_open_response *)message_body->data); break; case SML_MESSAGE_CLOSE_REQUEST: sml_close_request_free((sml_close_request *)message_body->data); break; case SML_MESSAGE_CLOSE_RESPONSE: sml_close_response_free((sml_close_response *)message_body->data); break; case SML_MESSAGE_GET_PROFILE_PACK_REQUEST: sml_get_profile_pack_request_free((sml_get_profile_pack_request *)message_body->data); break; case SML_MESSAGE_GET_PROFILE_PACK_RESPONSE: sml_get_profile_pack_response_free((sml_get_profile_pack_response *)message_body->data); break; case SML_MESSAGE_GET_PROFILE_LIST_REQUEST: sml_get_profile_list_request_free((sml_get_profile_list_request *)message_body->data); break; case SML_MESSAGE_GET_PROFILE_LIST_RESPONSE: sml_get_profile_list_response_free((sml_get_profile_list_response *)message_body->data); break; case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST: sml_get_proc_parameter_request_free( (sml_get_proc_parameter_request *)message_body->data); break; case SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE: sml_get_proc_parameter_response_free( (sml_get_proc_parameter_response *)message_body->data); break; case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST: sml_set_proc_parameter_request_free( (sml_set_proc_parameter_request *)message_body->data); break; case SML_MESSAGE_GET_LIST_REQUEST: sml_get_list_request_free((sml_get_list_request *)message_body->data); break; case SML_MESSAGE_GET_LIST_RESPONSE: sml_get_list_response_free((sml_get_list_response *)message_body->data); break; case SML_MESSAGE_ATTENTION_RESPONSE: sml_attention_response_free((sml_attention_response *)message_body->data); break; default: fprintf(stderr, "libsml: NYI: %s for message type %04X\n", __func__, *(message_body->tag)); break; } sml_number_free(message_body->tag); free(message_body); } } sml/src/sml_number.c000066400000000000000000000064061455045705600147700ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include #define SML_BIG_ENDIAN 1 #define SML_LITTLE_ENDIAN 0 static void sml_number_byte_swap(unsigned char *bytes, int bytes_len) { int i; unsigned char ob[bytes_len]; memcpy(&ob, bytes, bytes_len); for (i = 0; i < bytes_len; i++) bytes[i] = ob[bytes_len - (i + 1)]; } static int sml_number_endian() { int i = 1; char *p = (char *)&i; if (p[0] == 1) return SML_LITTLE_ENDIAN; else return SML_BIG_ENDIAN; } void *sml_number_init(u64 number, unsigned char type __attribute__((unused)), int size) { const char *bytes = (const char *)&number; // Swap bytes of big-endian number so that // memcpy copies the right part if (sml_number_endian() == SML_BIG_ENDIAN) { bytes += sizeof(u64) - size; } char *np = malloc(size); if (np == NULL) { goto error; } memcpy(np, bytes, size); return np; error: return NULL; } void *sml_number_parse(sml_buffer *buf, unsigned char type, int max_size) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } int l, i; unsigned char b; short negative_int = 0; if ((buf->cursor + 1) > buf->buffer_len) { // at least 1 byte for type? buf->error = 1; return NULL; } if (sml_buf_get_next_type(buf) != type) { buf->error = 1; return NULL; } l = sml_buf_get_next_length(buf); if (l < 0 || l > max_size) { buf->error = 1; return NULL; } unsigned char *np = malloc(max_size); memset(np, 0, max_size); // at least l bytes available? if ((buf->cursor + l) > buf->buffer_len) { buf->error = 1; free(np); return NULL; } if ((buf->cursor + 1) > buf->buffer_len) { // at least 1 byte? buf->error = 1; free(np); return NULL; } b = sml_buf_get_current_byte(buf); if (type == SML_TYPE_INTEGER && (b & 128)) { negative_int = 1; } int missing_bytes = max_size - l; memcpy(&(np[missing_bytes]), sml_buf_get_current_buf(buf), l); if (negative_int) { for (i = 0; i < missing_bytes; i++) { np[i] = 0xFF; } } if (!(sml_number_endian() == SML_BIG_ENDIAN)) { sml_number_byte_swap(np, max_size); } sml_buf_update_bytes_read(buf, l); return np; } void sml_number_write(void *np, unsigned char type, int size, sml_buffer *buf) { if (np == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, type, size); memcpy(sml_buf_get_current_buf(buf), np, size); if (!(sml_number_endian() == SML_BIG_ENDIAN)) { sml_number_byte_swap(sml_buf_get_current_buf(buf), size); } sml_buf_update_bytes_read(buf, size); } void sml_number_free(void *np) { if (np) { free(np); } } sml/src/sml_octet_string.c000066400000000000000000000077041455045705600162060ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include #include #include #ifndef SML_NO_UUID_LIB #include #else #include // for rand() #endif uint8_t ctoi(uint8_t c); uint8_t c2toi(uint8_t c1, uint8_t c2); uint8_t c2ptoi(char *c); octet_string *sml_octet_string_init(unsigned char *str, int length) { octet_string *s = (octet_string *)malloc(sizeof(octet_string)); *s = (octet_string){.str = NULL, .len = 0}; if (length > 0) { s->str = (unsigned char *)malloc(length); memcpy(s->str, str, length); s->len = length; } return s; } octet_string *sml_octet_string_init_from_hex(char *str) { int i, len = strlen(str); if (len % 2 != 0) { return NULL; } unsigned char bytes[len / 2]; for (i = 0; i < (len / 2); i++) { bytes[i] = c2ptoi(&(str[i * 2])); } return sml_octet_string_init(bytes, len / 2); } void sml_octet_string_free(octet_string *str) { if (str) { if (str->str) { free(str->str); } free(str); } } octet_string *sml_octet_string_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } int l; if (sml_buf_get_next_type(buf) != SML_TYPE_OCTET_STRING) { buf->error = 1; return NULL; } l = sml_buf_get_next_length(buf); if (l < 0 || l >= (buf->buffer_len - buf->cursor)) { // sanity check: doesnt fit into buffer... // libFuzzer fix for crash-3b12f21fdd346700ac1a10dfebba7604be8f070c buf->error = 1; return NULL; } octet_string *str = sml_octet_string_init(sml_buf_get_current_buf(buf), l); sml_buf_update_bytes_read(buf, l); return str; } void sml_octet_string_write(octet_string *str, sml_buffer *buf) { if (str == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_OCTET_STRING, (unsigned int)str->len); memcpy(sml_buf_get_current_buf(buf), str->str, str->len); buf->cursor += str->len; } octet_string *sml_octet_string_generate_uuid() { #ifndef SML_NO_UUID_LIB uuid_t uuid; uuid_generate(uuid); #else unsigned char uuid[16]; // TODO add support for WIN32 systems #ifdef __linux__ int fd = open("/dev/urandom", O_RDONLY); read(fd, uuid, 16); #else int i; for (i = 0; i < 16; i++) { uuid[i] = rand() % 0xFF; } #endif /* __linux__ */ uuid[6] = (uuid[6] & 0x0F) | 0x40; // set version uuid[8] = (uuid[8] & 0x3F) | 0x80; // set reserved bits #endif /* SML_NO_UUID_LIB */ return sml_octet_string_init(uuid, 16); } int sml_octet_string_cmp(octet_string *s1, octet_string *s2) { if (s1->len != s2->len) { return -1; } return memcmp(s1->str, s2->str, s1->len); } int sml_octet_string_cmp_with_hex(octet_string *str, char *hex) { octet_string *hstr = sml_octet_string_init_from_hex(hex); if (str->len != hstr->len) { sml_octet_string_free(hstr); return -1; } int result = memcmp(str->str, hstr->str, str->len); sml_octet_string_free(hstr); return result; } uint8_t ctoi(uint8_t c) { uint8_t ret = 0; if ((c >= '0') && (c <= '9')) { ret = c - '0'; } else if ((c >= 'a') && (c <= 'f')) { ret = c - 'a' + 10; } else if ((c >= 'A') && (c <= 'F')) { ret = c - 'A' + 10; } return ret; } uint8_t c2toi(uint8_t c1, uint8_t c2) { return ctoi(c1) << 4 | ctoi(c2); } uint8_t c2ptoi(char *c) { return ctoi((uint8_t)c[0]) << 4 | ctoi((uint8_t)c[1]); } sml/src/sml_open_request.c000066400000000000000000000057111455045705600162070ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include sml_open_request *sml_open_request_init() { sml_open_request *open_request = (sml_open_request *)malloc(sizeof(sml_open_request)); *open_request = (sml_open_request){.codepage = NULL, .client_id = NULL, .req_file_id = NULL, .server_id = NULL, .username = NULL, .password = NULL, .sml_version = NULL}; return open_request; } sml_open_request *sml_open_request_parse(sml_buffer *buf) { sml_open_request *msg = sml_open_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 7) { buf->error = 1; goto error; } msg->codepage = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->client_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->req_file_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->sml_version = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_open_request_free(msg); return NULL; } void sml_open_request_write(sml_open_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7); sml_octet_string_write(msg->codepage, buf); sml_octet_string_write(msg->client_id, buf); sml_octet_string_write(msg->req_file_id, buf); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username, buf); sml_octet_string_write(msg->password, buf); sml_u8_write(msg->sml_version, buf); } void sml_open_request_free(sml_open_request *msg) { if (msg) { sml_octet_string_free(msg->codepage); sml_octet_string_free(msg->client_id); sml_octet_string_free(msg->req_file_id); sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); sml_number_free(msg->sml_version); free(msg); } } sml/src/sml_open_response.c000066400000000000000000000052731455045705600163600ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include sml_open_response *sml_open_response_init() { sml_open_response *msg = (sml_open_response *)malloc(sizeof(sml_open_response)); *msg = (sml_open_response){.codepage = NULL, .client_id = NULL, .req_file_id = NULL, .server_id = NULL, .ref_time = NULL, .sml_version = NULL}; return msg; } sml_open_response *sml_open_response_parse(sml_buffer *buf) { sml_open_response *msg = sml_open_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 6) { buf->error = 1; goto error; } msg->codepage = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->client_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->req_file_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->ref_time = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->sml_version = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_open_response_free(msg); return NULL; } void sml_open_response_write(sml_open_response *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 6); sml_octet_string_write(msg->codepage, buf); sml_octet_string_write(msg->client_id, buf); sml_octet_string_write(msg->req_file_id, buf); sml_octet_string_write(msg->server_id, buf); sml_time_write(msg->ref_time, buf); sml_u8_write(msg->sml_version, buf); } void sml_open_response_free(sml_open_response *msg) { if (msg) { sml_octet_string_free(msg->codepage); sml_octet_string_free(msg->client_id); sml_octet_string_free(msg->req_file_id); sml_octet_string_free(msg->server_id); sml_time_free(msg->ref_time); sml_number_free(msg->sml_version); free(msg); } } sml/src/sml_set_proc_parameter_request.c000066400000000000000000000053421455045705600211240ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include sml_set_proc_parameter_request *sml_set_proc_parameter_request_init() { sml_set_proc_parameter_request *msg = (sml_set_proc_parameter_request *)malloc(sizeof(sml_set_proc_parameter_request)); *msg = (sml_set_proc_parameter_request){.server_id = NULL, .username = NULL, .password = NULL, .parameter_tree_path = NULL, .parameter_tree = NULL}; return msg; } sml_set_proc_parameter_request *sml_set_proc_parameter_request_parse(sml_buffer *buf) { sml_set_proc_parameter_request *msg = sml_set_proc_parameter_request_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 5) { buf->error = 1; goto error; } msg->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->username = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->password = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree_path = sml_tree_path_parse(buf); if (sml_buf_has_errors(buf)) goto error; msg->parameter_tree = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_set_proc_parameter_request_free(msg); return NULL; } void sml_set_proc_parameter_request_write(sml_set_proc_parameter_request *msg, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); sml_octet_string_write(msg->server_id, buf); sml_octet_string_write(msg->username, buf); sml_octet_string_write(msg->password, buf); sml_tree_path_write(msg->parameter_tree_path, buf); sml_tree_write(msg->parameter_tree, buf); } void sml_set_proc_parameter_request_free(sml_set_proc_parameter_request *msg) { if (msg) { sml_octet_string_free(msg->server_id); sml_octet_string_free(msg->username); sml_octet_string_free(msg->password); sml_tree_path_free(msg->parameter_tree_path); sml_tree_free(msg->parameter_tree); free(msg); } } sml/src/sml_shared.c000066400000000000000000000103671455045705600147470ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include int sml_buf_get_next_length(sml_buffer *buf) { int length = 0; // current byte available? if ((buf->cursor + 1) > buf->buffer_len) { buf->error = 1; return -1; } unsigned char byte = sml_buf_get_current_byte(buf); int list = ((byte & SML_TYPE_FIELD) == SML_TYPE_LIST) ? 0 : -1; for (; buf->cursor < buf->buffer_len;) { byte = sml_buf_get_current_byte(buf); length <<= 4; length |= (byte & SML_LENGTH_FIELD); if ((byte & SML_ANOTHER_TL) != SML_ANOTHER_TL) { break; } sml_buf_update_bytes_read(buf, 1); if (list) { list += -1; } } if (buf->cursor < buf->buffer_len) { sml_buf_update_bytes_read(buf, 1); } else { buf->error = 1; return -1; } return length + list; } void sml_buf_set_type_and_length(sml_buffer *buf, unsigned int type, unsigned int l) { // set the type buf->buffer[buf->cursor] = type; if (type != SML_TYPE_LIST) { l++; } if (l > SML_LENGTH_FIELD) { // how much shifts are necessary int mask_pos = (sizeof(unsigned int) * 2) - 1; // the 4 most significant bits of l (1111 0000 0000 ...) unsigned int mask = 0xF0 << (8 * (sizeof(unsigned int) - 1)); // select the next 4 most significant bits with a bit set until there // is something while (!(mask & l)) { mask >>= 4; mask_pos--; } l += mask_pos; // for every TL-field if ((0x0F << (4 * (mask_pos + 1))) & l) { // for the rare case that the addition of the number of TL-fields // result in another TL-field. mask_pos++; l++; } // copy 4 bits of the number to the buffer while (mask > SML_LENGTH_FIELD) { buf->buffer[buf->cursor] |= SML_ANOTHER_TL; buf->buffer[buf->cursor] |= ((mask & l) >> (4 * mask_pos)); mask >>= 4; mask_pos--; buf->cursor++; } } buf->buffer[buf->cursor] |= (l & SML_LENGTH_FIELD); buf->cursor++; } int sml_buf_has_errors(sml_buffer *buf) { return buf->error != 0; } int sml_buf_get_next_type(sml_buffer *buf) { if (buf->cursor >= buf->buffer_len) { buf->error = 1; return 0x100; // invalid type. } else return (buf->buffer[buf->cursor] & SML_TYPE_FIELD); } unsigned char sml_buf_get_current_byte(sml_buffer *buf) { return buf->buffer[buf->cursor]; } unsigned char *sml_buf_get_current_buf(sml_buffer *buf) { return &(buf->buffer[buf->cursor]); } void sml_buf_update_bytes_read(sml_buffer *buf, int bytes) { buf->cursor += bytes; } sml_buffer *sml_buffer_init(size_t length) { sml_buffer *buf = (sml_buffer *)malloc(sizeof(sml_buffer)); *buf = (sml_buffer){.buffer = NULL, .buffer_len = 0, .cursor = 0, .error = 0, .error_msg = NULL}; buf->buffer = (unsigned char *)malloc(length); buf->buffer_len = length; memset(buf->buffer, 0, buf->buffer_len); return buf; } void sml_buf_optional_write(sml_buffer *buf) { buf->buffer[buf->cursor] = SML_OPTIONAL_SKIPPED; buf->cursor++; } void sml_buffer_free(sml_buffer *buf) { if (buf) { if (buf->buffer) free(buf->buffer); if (buf->error_msg) free(buf->error_msg); free(buf); } } int sml_buf_optional_is_skipped(sml_buffer *buf) { if (buf->cursor >= buf->buffer_len) { buf->error = 1; return -1; } if (sml_buf_get_current_byte(buf) == SML_OPTIONAL_SKIPPED) { if (buf->cursor + 1 > buf->buffer_len) { buf->error = 1; return -1; } sml_buf_update_bytes_read(buf, 1); return 1; } return 0; } void sml_hexdump(unsigned char *buffer, size_t buffer_len) { for (size_t i = 0; i < buffer_len; i++) { printf("%02X ", (unsigned char)buffer[i]); if ((i + 1) % 8 == 0) { printf("\n"); } } puts(""); } sml/src/sml_status.c000066400000000000000000000037671455045705600150320ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include sml_status *sml_status_init() { sml_status *status = (sml_status *)malloc(sizeof(sml_status)); *status = (sml_status){.type = SML_TYPE_UNSIGNED, .data.status8 = NULL}; return status; } sml_status *sml_status_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } int max = 1; int type = sml_buf_get_next_type(buf); unsigned char byte = sml_buf_get_current_byte(buf); sml_status *status = sml_status_init(); status->type = type; switch (type) { case SML_TYPE_UNSIGNED: // get maximal size, if not all bytes are used (example: only 6 bytes for a u64) while (max < ((byte & SML_LENGTH_FIELD) - 1)) { max <<= 1; } status->data.status8 = sml_number_parse(buf, type, max); status->type |= max; break; default: buf->error = 1; break; } if (sml_buf_has_errors(buf)) { sml_status_free(status); return NULL; } return status; } void sml_status_write(sml_status *status, sml_buffer *buf) { if (status == 0) { sml_buf_optional_write(buf); return; } sml_number_write(status->data.status8, (status->type & SML_TYPE_FIELD), (status->type & SML_LENGTH_FIELD), buf); } void sml_status_free(sml_status *status) { if (status) { sml_number_free(status->data.status8); free(status); } } sml/src/sml_time.c000066400000000000000000000066371455045705600144440ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include #include sml_time *sml_time_init() { sml_time *t = (sml_time *)malloc(sizeof(sml_time)); *t = (sml_time){.tag = NULL, .data.sec_index = NULL}; return t; } sml_time *sml_time_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } sml_time *tme = sml_time_init(); // workaround Holley DTZ541 // if SML_ListEntry valTime (SML_Time) is given there are missing bytes: // 0x72: indicate a list for SML_Time with 2 entries // 0x62 0x01: indicate secIndex // instead, the DTZ541 starts with 0x65 + 4 bytes secIndex // the workaround will add this information during parsing if (sml_buf_get_current_byte(buf) == (SML_TYPE_UNSIGNED | 5)) { tme->tag = malloc(sizeof(u8)); *(tme->tag) = SML_TIME_SEC_INDEX; } else { if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 2) { buf->error = 1; goto error; } tme->tag = sml_u8_parse(buf); if (sml_buf_has_errors(buf)) goto error; } int type = sml_buf_get_next_type(buf); switch (type) { case SML_TYPE_UNSIGNED: tme->data.timestamp = sml_u32_parse(buf); if (sml_buf_has_errors(buf)) goto error; break; case SML_TYPE_LIST: // Some meters (e.g. FROETEC Multiflex ZG22) giving not one uint32 // as timestamp, but a list of 3 values. // Ignoring these values, so that parsing does not fail. sml_buf_get_next_length(buf); // should we check the length here? u32 *t1 = sml_u32_parse(buf); if (sml_buf_has_errors(buf)) { if (t1) sml_number_free(t1); goto error; } i16 *t2 = sml_i16_parse(buf); if (sml_buf_has_errors(buf)) { if (t1) sml_number_free(t1); if (t2) sml_number_free(t2); goto error; } i16 *t3 = sml_i16_parse(buf); if (sml_buf_has_errors(buf)) { if (t1) sml_number_free(t1); if (t2) sml_number_free(t2); if (t3) sml_number_free(t3); goto error; } fprintf( stderr, "libsml: error: sml_time as list[3]: ignoring value[0]=%u value[1]=%d value[2]=%d\n", t1 ? *t1 : 0, t2 ? *t2 : 0, t3 ? *t3 : 0); if (t1) sml_number_free(t1); if (t2) sml_number_free(t2); if (t3) sml_number_free(t3); break; default: goto error; } return tme; error: sml_time_free(tme); return NULL; } void sml_time_write(sml_time *t, sml_buffer *buf) { if (t == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); sml_u8_write(t->tag, buf); sml_u32_write(t->data.timestamp, buf); } void sml_time_free(sml_time *tme) { if (tme) { sml_number_free(tme->tag); sml_number_free(tme->data.timestamp); free(tme); } } sml/src/sml_transport.c000066400000000000000000000077131455045705600155360ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include // for errno #include #include #include #include #include #include #include #include #define MC_SML_BUFFER_LEN 8096 unsigned char esc_seq[] = {0x1b, 0x1b, 0x1b, 0x1b}; unsigned char start_seq[] = {0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01}; unsigned char end_seq[] = {0x1b, 0x1b, 0x1b, 0x1b, 0x1a}; size_t sml_read(int fd, fd_set *set, unsigned char *buffer, size_t len) { ssize_t r = 0; size_t tr = 0; while (tr < len) { select(fd + 1, set, 0, 0, 0); if (FD_ISSET(fd, set)) { r = read(fd, &(buffer[tr]), len - tr); if (r == 0) return 0; // EOF if (r < 0) { if (errno == EINTR || errno == EAGAIN) continue; // should be ignored fprintf(stderr, "libsml: sml_read(): read error\n"); return 0; } tr += r; } } return tr; } size_t sml_transport_read(int fd, unsigned char *buffer, size_t max_len) { fd_set readfds; FD_ZERO(&readfds); FD_SET(fd, &readfds); unsigned char buf[max_len]; memset(buf, 0, max_len); unsigned int len = 0; if (max_len < 8) { // prevent buffer overflow fprintf(stderr, "libsml: error: sml_transport_read(): passed buffer too small!\n"); return 0; } while (len < 8) { if (sml_read(fd, &readfds, &(buf[len]), 1) == 0) { return 0; } if ((buf[len] == 0x1b && len < 4) || (buf[len] == 0x01 && len >= 4)) { len++; } else { len = 0; } } // found start sequence while ((len + 8) < max_len) { if (sml_read(fd, &readfds, &(buf[len]), 4) == 0) { return 0; } if (memcmp(&buf[len], esc_seq, 4) == 0) { // found esc sequence len += 4; if (sml_read(fd, &readfds, &(buf[len]), 4) == 0) { return 0; } if (buf[len] == 0x1a) { // found end sequence len += 4; memcpy(buffer, &(buf[0]), len); return len; } else { // don't read other escaped sequences yet fprintf(stderr, "libsml: error: unrecognized sequence\n"); return 0; } } len += 4; } return 0; } void sml_transport_listen(int fd, void (*sml_transport_receiver)(unsigned char *buffer, size_t buffer_len)) { unsigned char buffer[MC_SML_BUFFER_LEN]; size_t bytes; while ((bytes = sml_transport_read(fd, buffer, MC_SML_BUFFER_LEN)) > 0) { sml_transport_receiver(buffer, bytes); } } int sml_transport_write(int fd, sml_file *file) { sml_buffer *buf = file->buf; buf->cursor = 0; // add start sequence memcpy(sml_buf_get_current_buf(buf), start_seq, 8); buf->cursor += 8; // add file sml_file_write(file); // add padding bytes int padding = (buf->cursor % 4) ? (4 - buf->cursor % 4) : 0; if (padding) { // write zeroed bytes memset(sml_buf_get_current_buf(buf), 0, padding); buf->cursor += padding; } // begin end sequence memcpy(sml_buf_get_current_buf(buf), end_seq, 5); buf->cursor += 5; // add padding info buf->buffer[buf->cursor++] = (unsigned char)padding; // add crc checksum u16 crc = sml_crc16_calculate(buf->buffer, buf->cursor); buf->buffer[buf->cursor++] = (unsigned char)((crc & 0xFF00) >> 8); buf->buffer[buf->cursor++] = (unsigned char)(crc & 0x00FF); size_t wr = write(fd, buf->buffer, buf->cursor); if (wr == buf->cursor) { return wr; } return 0; } sml/src/sml_tree.c000066400000000000000000000352611455045705600144400ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include // sml_tree_path; sml_tree_path *sml_tree_path_init() { sml_tree_path *tree_path = (sml_tree_path *)malloc(sizeof(sml_tree_path)); *tree_path = (sml_tree_path){.path_entries_len = 0, .path_entries = NULL}; return tree_path; } sml_tree_path *sml_tree_path_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } sml_tree_path *tree_path = sml_tree_path_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { goto error; } octet_string *s; int elems; for (elems = sml_buf_get_next_length(buf); elems > 0; elems--) { s = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (s) { sml_tree_path_add_path_entry(tree_path, s); } } return tree_path; error: buf->error = 1; sml_tree_path_free(tree_path); return NULL; } void sml_tree_path_add_path_entry(sml_tree_path *tree_path, octet_string *entry) { tree_path->path_entries_len++; tree_path->path_entries = (octet_string **)realloc( tree_path->path_entries, sizeof(octet_string *) * tree_path->path_entries_len); tree_path->path_entries[tree_path->path_entries_len - 1] = entry; } void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf) { if (tree_path == 0) { sml_buf_optional_write(buf); return; } if (tree_path->path_entries && tree_path->path_entries_len > 0) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, tree_path->path_entries_len); int i; for (i = 0; i < tree_path->path_entries_len; i++) { sml_octet_string_write(tree_path->path_entries[i], buf); } } } void sml_tree_path_free(sml_tree_path *tree_path) { if (tree_path) { if (tree_path->path_entries && tree_path->path_entries_len > 0) { int i; for (i = 0; i < tree_path->path_entries_len; i++) { sml_octet_string_free(tree_path->path_entries[i]); } free(tree_path->path_entries); } free(tree_path); } } // sml_tree; sml_tree *sml_tree_init() { sml_tree *tree = (sml_tree *)malloc(sizeof(sml_tree)); *tree = (sml_tree){ .parameter_name = NULL, .parameter_value = NULL, .child_list = NULL, .child_list_len = 0}; return tree; } sml_tree *sml_tree_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } sml_tree *tree = sml_tree_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 3) { buf->error = 1; goto error; } tree->parameter_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; tree->parameter_value = sml_proc_par_value_parse(buf); if (sml_buf_has_errors(buf)) goto error; if (!sml_buf_optional_is_skipped(buf)) { if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } sml_tree *c; int elems; for (elems = sml_buf_get_next_length(buf); elems > 0; elems--) { c = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) { if (c) sml_tree_free(c); goto error; } if (c) { sml_tree_add_tree(tree, c); } } } return tree; error: sml_tree_free(tree); return NULL; } void sml_tree_add_tree(sml_tree *base_tree, sml_tree *tree) { base_tree->child_list_len++; base_tree->child_list = (sml_tree **)realloc(base_tree->child_list, sizeof(sml_tree *) * base_tree->child_list_len); base_tree->child_list[base_tree->child_list_len - 1] = tree; } void sml_tree_free(sml_tree *tree) { if (tree) { sml_octet_string_free(tree->parameter_name); sml_proc_par_value_free(tree->parameter_value); int i; for (i = 0; i < tree->child_list_len; i++) { sml_tree_free(tree->child_list[i]); } free(tree->child_list); free(tree); } } void sml_tree_write(sml_tree *tree, sml_buffer *buf) { if (tree == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3); sml_octet_string_write(tree->parameter_name, buf); sml_proc_par_value_write(tree->parameter_value, buf); if (tree->child_list && tree->child_list_len > 0) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, tree->child_list_len); int i; for (i = 0; i < tree->child_list_len; i++) { sml_tree_write(tree->child_list[i], buf); } } else { sml_buf_optional_write(buf); } } // sml_proc_par_value; sml_proc_par_value *sml_proc_par_value_init() { sml_proc_par_value *value = (sml_proc_par_value *)malloc(sizeof(sml_proc_par_value)); *value = (sml_proc_par_value){.tag = NULL, .data.value = NULL}; return value; } sml_proc_par_value *sml_proc_par_value_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } sml_proc_par_value *ppv = sml_proc_par_value_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 2) { buf->error = 1; goto error; } ppv->tag = sml_u8_parse(buf); if (sml_buf_has_errors(buf) || !(ppv->tag)) goto error; switch (*(ppv->tag)) { case SML_PROC_PAR_VALUE_TAG_VALUE: ppv->data.value = sml_value_parse(buf); break; case SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY: ppv->data.period_entry = sml_period_entry_parse(buf); break; case SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY: ppv->data.tupel_entry = sml_tupel_entry_parse(buf); break; case SML_PROC_PAR_VALUE_TAG_TIME: ppv->data.time = sml_time_parse(buf); break; default: buf->error = 1; goto error; } return ppv; error: sml_proc_par_value_free(ppv); return NULL; } void sml_proc_par_value_write(sml_proc_par_value *value, sml_buffer *buf) { if (value == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); sml_u8_write(value->tag, buf); switch (*(value->tag)) { case SML_PROC_PAR_VALUE_TAG_VALUE: sml_value_write(value->data.value, buf); break; case SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY: sml_period_entry_write(value->data.period_entry, buf); break; case SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY: sml_tupel_entry_write(value->data.tupel_entry, buf); break; case SML_PROC_PAR_VALUE_TAG_TIME: sml_time_write(value->data.time, buf); break; default: fprintf(stderr, "libsml: error: unknown tag in %s\n", __func__); } } void sml_proc_par_value_free(sml_proc_par_value *ppv) { if (ppv) { if (ppv->tag) { switch (*(ppv->tag)) { case SML_PROC_PAR_VALUE_TAG_VALUE: sml_value_free(ppv->data.value); break; case SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY: sml_period_entry_free(ppv->data.period_entry); break; case SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY: sml_tupel_entry_free(ppv->data.tupel_entry); break; case SML_PROC_PAR_VALUE_TAG_TIME: sml_time_free(ppv->data.time); break; default: if (ppv->data.value) { free(ppv->data.value); } } sml_number_free(ppv->tag); } else { // Without the tag, there might be a memory leak. if (ppv->data.value) { free(ppv->data.value); } } free(ppv); } } // sml_tuple_entry; sml_tupel_entry *sml_tupel_entry_init() { sml_tupel_entry *tupel = (sml_tupel_entry *)malloc(sizeof(sml_tupel_entry)); *tupel = (sml_tupel_entry){.server_id = NULL, .sec_index = NULL, .status = NULL, .unit_pA = NULL, .scaler_pA = NULL, .value_pA = NULL, .unit_R1 = NULL, .scaler_R1 = NULL, .value_R1 = NULL, .unit_R4 = NULL, .scaler_R4 = NULL, .value_R4 = NULL, .signature_pA_R1_R4 = NULL, .unit_mA = NULL, .scaler_mA = NULL, .value_mA = NULL, .unit_R2 = NULL, .scaler_R2 = NULL, .value_R2 = NULL, .unit_R3 = NULL, .scaler_R3 = NULL, .value_R3 = NULL, .signature_mA_R2_R3 = NULL}; return tupel; } sml_tupel_entry *sml_tupel_entry_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } sml_tupel_entry *tupel = sml_tupel_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 23) { buf->error = 1; goto error; } tupel->server_id = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->sec_index = sml_time_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->status = sml_u64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_pA = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_pA = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_pA = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_R1 = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_R1 = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_R1 = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_R4 = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_R4 = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_R4 = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->signature_pA_R1_R4 = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_mA = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_mA = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_mA = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_R2 = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_R2 = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_R2 = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->unit_R3 = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->scaler_R3 = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->value_R3 = sml_i64_parse(buf); if (sml_buf_has_errors(buf)) goto error; tupel->signature_mA_R2_R3 = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return tupel; error: sml_tupel_entry_free(tupel); return NULL; } void sml_tupel_entry_write(sml_tupel_entry *tupel, sml_buffer *buf) { if (tupel == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 23); sml_octet_string_write(tupel->server_id, buf); sml_time_write(tupel->sec_index, buf); sml_u64_write(tupel->status, buf); sml_unit_write(tupel->unit_pA, buf); sml_i8_write(tupel->scaler_pA, buf); sml_i64_write(tupel->value_pA, buf); sml_unit_write(tupel->unit_R1, buf); sml_i8_write(tupel->scaler_R1, buf); sml_i64_write(tupel->value_R1, buf); sml_unit_write(tupel->unit_R4, buf); sml_i8_write(tupel->scaler_R4, buf); sml_i64_write(tupel->value_R4, buf); sml_octet_string_write(tupel->signature_pA_R1_R4, buf); sml_unit_write(tupel->unit_mA, buf); sml_i8_write(tupel->scaler_mA, buf); sml_i64_write(tupel->value_mA, buf); sml_unit_write(tupel->unit_R2, buf); sml_i8_write(tupel->scaler_R2, buf); sml_i64_write(tupel->value_R2, buf); sml_unit_write(tupel->unit_R3, buf); sml_i8_write(tupel->scaler_R3, buf); sml_i64_write(tupel->value_R3, buf); sml_octet_string_write(tupel->signature_mA_R2_R3, buf); } void sml_tupel_entry_free(sml_tupel_entry *tupel) { if (tupel) { sml_octet_string_free(tupel->server_id); sml_time_free(tupel->sec_index); sml_number_free(tupel->status); sml_unit_free(tupel->unit_pA); sml_number_free(tupel->scaler_pA); sml_number_free(tupel->value_pA); sml_unit_free(tupel->unit_R1); sml_number_free(tupel->scaler_R1); sml_number_free(tupel->value_R1); sml_unit_free(tupel->unit_R4); sml_number_free(tupel->scaler_R4); sml_number_free(tupel->value_R4); sml_octet_string_free(tupel->signature_pA_R1_R4); sml_unit_free(tupel->unit_mA); sml_number_free(tupel->scaler_mA); sml_number_free(tupel->value_mA); sml_unit_free(tupel->unit_R2); sml_number_free(tupel->scaler_R2); sml_number_free(tupel->value_R2); sml_unit_free(tupel->unit_R3); sml_number_free(tupel->scaler_R3); sml_number_free(tupel->value_R3); sml_octet_string_free(tupel->signature_mA_R2_R3); free(tupel); } } // sml_period_entry; sml_period_entry *sml_period_entry_init() { sml_period_entry *period = (sml_period_entry *)malloc(sizeof(sml_period_entry)); *period = (sml_period_entry){ .obj_name = NULL, .unit = NULL, .scaler = NULL, .value = NULL, .value_signature = NULL}; return period; } static void *sml_period_entry_parse_(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } sml_period_entry *period = sml_period_entry_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; goto error; } if (sml_buf_get_next_length(buf) != 5) { buf->error = 1; goto error; } period->obj_name = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; period->unit = sml_unit_parse(buf); if (sml_buf_has_errors(buf)) goto error; period->scaler = sml_i8_parse(buf); if (sml_buf_has_errors(buf)) goto error; period->value = sml_value_parse(buf); if (sml_buf_has_errors(buf)) goto error; period->value_signature = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; return period; error: sml_period_entry_free(period); return NULL; } sml_period_entry *sml_period_entry_parse(sml_buffer *buf) { return sml_period_entry_parse_(buf); } void sml_period_entry_write(sml_period_entry *period, sml_buffer *buf) { if (period == 0) { sml_buf_optional_write(buf); return; } sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5); sml_octet_string_write(period->obj_name, buf); sml_unit_write(period->unit, buf); sml_i8_write(period->scaler, buf); sml_value_write(period->value, buf); sml_octet_string_write(period->value_signature, buf); } static void sml_period_entry_free_(void *p) { sml_period_entry *period = p; if (period) { sml_octet_string_free(period->obj_name); sml_unit_free(period->unit); sml_number_free(period->scaler); sml_value_free(period->value); sml_octet_string_free(period->value_signature); free(period); } } void sml_period_entry_free(sml_period_entry *period) { sml_period_entry_free_(period); } sml/src/sml_value.c000066400000000000000000000101641455045705600146100ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include #include #include sml_value *sml_value_parse(sml_buffer *buf) { if (sml_buf_optional_is_skipped(buf)) { return NULL; } int max = 1; int type = sml_buf_get_next_type(buf); unsigned char byte = sml_buf_get_current_byte(buf); sml_value *value = sml_value_init(); value->type = type; switch (type) { case SML_TYPE_OCTET_STRING: value->data.bytes = sml_octet_string_parse(buf); break; case SML_TYPE_BOOLEAN: value->data.boolean = sml_boolean_parse(buf); break; case SML_TYPE_UNSIGNED: case SML_TYPE_INTEGER: // get maximal size, if not all bytes are used (example: only 6 bytes for a u64) while (max < ((byte & SML_LENGTH_FIELD) - 1)) { max <<= 1; } value->data.uint8 = sml_number_parse(buf, type, max); value->type |= max; break; default: buf->error = 1; break; } if (sml_buf_has_errors(buf)) { sml_value_free(value); return NULL; } return value; } void sml_value_write(sml_value *value, sml_buffer *buf) { if (value == 0) { sml_buf_optional_write(buf); return; } switch (value->type & SML_TYPE_FIELD) { case SML_TYPE_OCTET_STRING: sml_octet_string_write(value->data.bytes, buf); break; case SML_TYPE_BOOLEAN: sml_boolean_write(value->data.boolean, buf); break; case SML_TYPE_UNSIGNED: case SML_TYPE_INTEGER: sml_number_write(value->data.uint8, (value->type & SML_TYPE_FIELD), (value->type & SML_LENGTH_FIELD), buf); break; } } sml_value *sml_value_init() { sml_value *value = (sml_value *)malloc(sizeof(sml_value)); *value = (sml_value){.type = SML_TYPE_OCTET_STRING, .data.bytes = NULL}; return value; } void sml_value_free(sml_value *value) { if (value) { switch (value->type) { case SML_TYPE_OCTET_STRING: sml_octet_string_free(value->data.bytes); break; case SML_TYPE_BOOLEAN: sml_boolean_free(value->data.boolean); break; default: sml_number_free(value->data.int8); break; } free(value); } } double sml_value_to_double(sml_value *value) { switch (value->type) { case 0x51: return *value->data.int8; break; case 0x52: return *value->data.int16; break; case 0x54: return *value->data.int32; break; case 0x58: return *value->data.int64; break; case 0x61: return *value->data.uint8; break; case 0x62: return *value->data.uint16; break; case 0x64: return *value->data.uint32; break; case 0x68: return *value->data.uint64; break; default: fprintf(stderr, "libsml: error: unknown type %d in %s\n", value->type, __func__); return 0; } } /* * Converts SML octet string to a printable hex string. * It allocates memory, don't forget to free the buffer after using. */ char *sml_value_to_strhex(sml_value *value, char **result, bool mixed) { const char hex_str[] = "0123456789abcdef"; if (value == NULL || value->data.bytes == NULL || value->data.bytes->str == NULL) return NULL; int len = value->data.bytes->len; unsigned char *str = value->data.bytes->str; // allocate 3 bytes per octet string byte (0x0f gets "0f ") *result = malloc(len * 3 + 1); if (*result == NULL) return NULL; char *res_ptr = *result; for (int i = 0; i < len; i++) { if (mixed && (str[i] > 0x20 && str[i] < 0x7b)) { *res_ptr++ = (char)str[i]; } else { mixed = false; *res_ptr++ = hex_str[(str[i] >> 4) & 0x0F]; *res_ptr++ = hex_str[str[i] & 0x0F]; *res_ptr++ = ' '; } } // mark end of string *res_ptr = 0; return *result; } test/000077500000000000000000000000001455045705600120505ustar00rootroot00000000000000test/Makefile000066400000000000000000000015421455045705600135120ustar00rootroot00000000000000UNAME := $(shell uname) CFLAGS += -I../sml/include/ -std=c99 -Wall -Wextra -pedantic LIBSML = ../sml/lib/libsml.a ifneq ($(UNAME), Darwin) LIBS = -luuid endif UNITY = \ unity/unity.o \ unity/unity_fixture.o OBJS = \ src/test_helper.o \ src/sml_octet_string_test.o \ src/sml_buffer_test.o \ src/sml_number_test.o \ src/sml_boolean_test.o \ src/sml_value_test.o \ src/sml_status_test.o \ src/sml_list_test.o \ src/sml_time_test.o \ src/sml_tree_test.o \ src/sml_file_test.o \ src/sml_open_request_test.o \ src/sml_get_profile_pack_request_test.o \ src/sml_message_test.o test_run: libsml test @./test test : $(UNITY) $(OBJS) $(LIBSML) $(CC) $(CFLAGS) $(LIBS) $^ test_main.c -o test $(LIBS) .PHONY: code libsml : @$(MAKE) -C ../sml %.o : %.c $(CC) $(CFLAGS) -c $^ -o $@ .PHONY: clean clean : @rm -f unity/*.o @rm -f src/*.o @rm -f test test/src/000077500000000000000000000000001455045705600126375ustar00rootroot00000000000000test/src/fuzzer.c000066400000000000000000000026211455045705600143310ustar00rootroot00000000000000// Copyright 2020 Matthias Behr // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { // we shift by 8 to be able to use libsml-testing bin files inside // corpus dir sml_file *file = sml_file_parse(size > 8 ? ((unsigned char *)data) + 8 : (unsigned char *)data, size > 8 ? (size - 8) : size); sml_file_free(file); return 0; } // compile with: // clang -g -O1 -L./sml/lib -fsanitize=fuzzer,address,undefined test/src/fuzzer.c `find sml/src/*.c` // -luuid -I ./sml/include // run with: // mkdir corpus_dir // prefill corpus_dir e.g. with files libsml-testing // ./a.out corpus_dir // run until it stops with a crash file being generated // e.g. crash-... // debug with e.g. // gdb --args ./a.out crash-... test/src/sml_boolean_test.c000066400000000000000000000051331455045705600163360ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_boolean); static sml_buffer *buf; TEST_SETUP(sml_boolean) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_boolean) { sml_buffer_free(buf); } TEST(sml_boolean, init) { sml_boolean *b = sml_boolean_init(SML_BOOLEAN_TRUE); TEST_ASSERT_NOT_NULL(b); TEST_ASSERT_EQUAL(SML_BOOLEAN_TRUE, *b); sml_boolean_free( b ); } TEST(sml_boolean, parse_true) { hex2binary("420F", sml_buf_get_current_buf(buf)); sml_boolean *b = sml_boolean_parse(buf); TEST_ASSERT_NOT_NULL(b); TEST_ASSERT_EQUAL(SML_BOOLEAN_TRUE, *b); sml_boolean_free( b ); } TEST(sml_boolean, parse_false) { hex2binary("4200", sml_buf_get_current_buf(buf)); sml_boolean *b = sml_boolean_parse(buf); TEST_ASSERT_NOT_NULL(b); TEST_ASSERT_EQUAL(SML_BOOLEAN_FALSE, *b); TEST_ASSERT_EQUAL(2, buf->cursor); sml_boolean_free( b ); } TEST(sml_boolean, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_boolean *b = sml_boolean_parse(buf); TEST_ASSERT_NULL(b); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); sml_boolean_free( b ); } TEST(sml_boolean, write_true) { sml_boolean *b = sml_boolean_init(SML_BOOLEAN_TRUE); sml_boolean_write(b, buf); expected_buf(buf, "42FF", 2); sml_boolean_free( b ); } TEST(sml_boolean, write_false) { sml_boolean *b = sml_boolean_init(SML_BOOLEAN_FALSE); sml_boolean_write(b, buf); expected_buf(buf, "4200", 2); sml_boolean_free( b ); } TEST(sml_boolean, write_optional) { sml_boolean_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_boolean) { RUN_TEST_CASE(sml_boolean, init); RUN_TEST_CASE(sml_boolean, parse_true); RUN_TEST_CASE(sml_boolean, parse_false); RUN_TEST_CASE(sml_boolean, parse_optional); RUN_TEST_CASE(sml_boolean, write_true); RUN_TEST_CASE(sml_boolean, write_false); RUN_TEST_CASE(sml_boolean, write_optional); } test/src/sml_buffer_test.c000066400000000000000000000025001455045705600161630ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include TEST_GROUP(sml_buffer); int buffer_len = 512; static sml_buffer *buf; TEST_SETUP(sml_buffer) { buf = sml_buffer_init(buffer_len); } TEST_TEAR_DOWN(sml_buffer) { sml_buffer_free( buf ); } TEST(sml_buffer, init_defaults) { TEST_ASSERT_NOT_NULL(buf); TEST_ASSERT_NOT_NULL(buf->buffer); TEST_ASSERT_EQUAL(buffer_len, buf->buffer_len); TEST_ASSERT_EQUAL(0, buf->cursor); TEST_ASSERT_EQUAL(0, buf->error); TEST_ASSERT_NULL(buf->error_msg); } TEST_GROUP_RUNNER(sml_buffer) { RUN_TEST_CASE(sml_buffer, init_defaults); } test/src/sml_file_test.c000066400000000000000000000050731455045705600156410ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_file); static sml_buffer *buf; TEST_SETUP(sml_file) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_file) { sml_buffer_free(buf); } TEST(sml_file, init) { sml_file *file = sml_file_init(); TEST_ASSERT_NOT_NULL(file); TEST_ASSERT_EQUAL(0, file->messages_len); TEST_ASSERT_NULL(file->messages); TEST_ASSERT_NOT_NULL(file->buf); sml_file_free( file ); } TEST(sml_file, parse_crash_report1) { unsigned char buffer[388 - 16]; // this is from an error / crash report from vzlogger. // with the following buffer (sadly only partial report) // and bytes=388 // it reports an error type 0900 not yet implemented // the fix was to check crc being not null unsigned char buffer2[] = "\033\033\033\033\001\001\001\001v\vESYA\037\350\005\265\203\021b\000b\000rc\001\001v\001" "\004ESY\bESY+" "\261\203\021\v\t\001ESY\021\003\246\037\350\001\001c\035R\000v\vESYA\037\350\005\265\203" "\022b\000b\000rc\t\000\001ESY\021\003\246\037\350\a\001\000b\n\377\377rb\001e\001\347+" "\261yw\a\201\201ǂ\003\377\001\001\001\001\004ESY\001w\a\001\000\000\000\t\377\001\001" "\001" "\001\v\t\001ESY\021\003\246\037\350\001w\a\001\000\001\b\000\377d\000\000\200\001b\036R" "\374Y\000\000\000\tr\231\221\004\001w\a\001\000\020\a\000\377\001\001b\033R\376Y\000\000" "\000\000\000\000i\231\001w\a\001\000$"; // sadly not... just 202 TEST_ASSERT_EQUAL(388, sizeof buffer2); memcpy(buffer, buffer2, sizeof buffer2); size_t bytes = 388; // bytes and buffer like from sml_transport_read sml_file *file = sml_file_parse(buffer + 8, bytes - 16); TEST_ASSERT_NOT_NULL(file); TEST_ASSERT_EQUAL(1, file->messages_len); sml_file_free(file); } TEST_GROUP_RUNNER(sml_file) { RUN_TEST_CASE(sml_file, init); RUN_TEST_CASE(sml_file, parse_crash_report1); } test/src/sml_get_profile_pack_request_test.c000066400000000000000000000035531455045705600217700ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_get_profile_pack_request); static sml_buffer *buf; TEST_SETUP(sml_get_profile_pack_request) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_get_profile_pack_request) { sml_buffer_free(buf); } TEST(sml_get_profile_pack_request, init) { sml_get_profile_pack_request *r = sml_get_profile_pack_request_init(); TEST_ASSERT_NOT_NULL(r); sml_get_profile_pack_request_free( r ); } TEST(sml_get_profile_pack_request, parse) { hex2binary("7901010101010101730648616C6C6F0648616C6C6F0648616C6C6F01", sml_buf_get_current_buf(buf)); sml_get_profile_pack_request *r = sml_get_profile_pack_request_parse(buf); TEST_ASSERT_NOT_NULL(r); TEST_ASSERT_NOT_NULL(r->object_list); TEST_ASSERT_NOT_NULL(r->object_list->next); TEST_ASSERT_NOT_NULL(r->object_list->next->next); TEST_ASSERT_NULL(r->object_list->next->next->next); sml_get_profile_pack_request_free( r ); } TEST_GROUP_RUNNER(sml_get_profile_pack_request) { RUN_TEST_CASE(sml_get_profile_pack_request, init); RUN_TEST_CASE(sml_get_profile_pack_request, parse); } test/src/sml_list_test.c000066400000000000000000000104731455045705600156750ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_list); static sml_buffer *buf; TEST_SETUP(sml_list) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_list) { sml_buffer_free(buf); } TEST(sml_list, init) { sml_list *l = sml_list_init(); TEST_ASSERT_NOT_NULL(l); TEST_ASSERT_NULL(l->next); sml_list_free( l ); } TEST(sml_list, add) { sml_list *l = sml_list_init(); sml_list *n = sml_list_init(); sml_list_add(l, n); TEST_ASSERT_NOT_NULL(l); TEST_ASSERT_NOT_NULL(l->next); TEST_ASSERT_TRUE(n == l->next); sml_list_free( l ); } TEST(sml_list, parse_two_entries) { hex2binary("727702610101010142000177026101010101420001", sml_buf_get_current_buf(buf)); sml_list *l = sml_list_parse(buf); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); TEST_ASSERT_NOT_NULL(l); TEST_ASSERT_NOT_NULL(l->next); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(l->obj_name, "61")); sml_list_free( l ); } TEST(sml_list, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_list *l = sml_list_parse(buf); TEST_ASSERT_NULL(l); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); sml_list_free( l ); } TEST(sml_list, write_one_entry) { sml_list *l = sml_list_init(); l->obj_name = sml_octet_string_init((unsigned char *)"Hallo", 5); l->value = sml_value_init(); l->value->type = SML_TYPE_OCTET_STRING; l->value->data.bytes = sml_octet_string_init((unsigned char *)"Hallo", 5); sml_list_write(l, buf); expected_buf(buf, "71770648616C6C6F010101010648616C6C6F01", 19); sml_list_free( l ); } TEST(sml_list, write_optional) { sml_list_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_list) { RUN_TEST_CASE(sml_list, init); RUN_TEST_CASE(sml_list, add); RUN_TEST_CASE(sml_list, parse_two_entries); RUN_TEST_CASE(sml_list, parse_optional); RUN_TEST_CASE(sml_list, write_one_entry); RUN_TEST_CASE(sml_list, write_optional); } TEST_GROUP(sml_sequence); static sml_buffer *buf; TEST_SETUP(sml_sequence) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_sequence) { sml_buffer_free(buf); } TEST(sml_sequence, init) { sml_sequence *seq = sml_sequence_init(&free); TEST_ASSERT_NOT_NULL(seq); sml_sequence_free( seq ); } static void * sml_octet_string_parse_( sml_buffer * buf ) { return sml_octet_string_parse( buf ); } static void sml_octet_string_free_( void * p ) { sml_octet_string_free( p ); } TEST(sml_sequence, parse_octet_string) { hex2binary("720648616C6C6F0648616C6C6F", sml_buf_get_current_buf(buf)); sml_sequence *seq = sml_sequence_parse(buf, sml_octet_string_parse_, sml_octet_string_free_); TEST_ASSERT_NOT_NULL(seq); TEST_ASSERT_EQUAL(2, seq->elems_len); sml_sequence_free( seq ); } static void sml_octet_string_write_( void * p, sml_buffer * buf ) { sml_octet_string_write( p, buf ); } TEST(sml_sequence, write_octet_string) { sml_sequence *seq = sml_sequence_init( sml_octet_string_free_ ); sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_sequence_write(seq, buf, sml_octet_string_write_ ); expected_buf(buf, "720648616C6C6F0648616C6C6F", 13); sml_sequence_free( seq ); } TEST(sml_sequence, free_octet_string) { sml_sequence *seq = sml_sequence_init( sml_octet_string_free_ ); sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_sequence_free(seq); } TEST_GROUP_RUNNER(sml_sequence) { RUN_TEST_CASE(sml_sequence, init); RUN_TEST_CASE(sml_sequence, parse_octet_string); RUN_TEST_CASE(sml_sequence, write_octet_string); RUN_TEST_CASE(sml_sequence, free_octet_string); } test/src/sml_message_test.c000066400000000000000000000042661455045705600163510ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_message); static sml_buffer *buf; TEST_SETUP(sml_message) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_message) { sml_buffer_free(buf); } TEST(sml_message, init) { sml_message *msg = sml_message_init(); TEST_ASSERT_NOT_NULL(msg); TEST_ASSERT_NOT_NULL(msg->transaction_id); sml_message_free( msg ); } TEST(sml_message, init_unique_transaction_id) { sml_message *msg1 = sml_message_init(); sml_message *msg2 = sml_message_init(); TEST_ASSERT_TRUE(sml_octet_string_cmp(msg1->transaction_id, msg2->transaction_id) != 0); sml_message_free( msg2 ); sml_message_free( msg1 ); } TEST(sml_message, parse) { hex2binary("7607003800003FB662006200726301017601010700380042153D0B06454D48010271533BCD010163820800", sml_buf_get_current_buf(buf)); sml_message *msg = sml_message_parse(buf); TEST_ASSERT_NOT_NULL(msg); sml_message_free( msg ); } TEST(sml_message, crc_error) { hex2binary("7607003800003FB662006200726301017601010700390042153D0B06454D48010271533BCD010163820800", sml_buf_get_current_buf(buf)); // ^ 1 bit corrupted here sml_message *msg = sml_message_parse(buf); TEST_ASSERT_NULL(msg); } TEST_GROUP_RUNNER(sml_message) { RUN_TEST_CASE(sml_message, init); RUN_TEST_CASE(sml_message, init_unique_transaction_id); RUN_TEST_CASE(sml_message, parse); RUN_TEST_CASE(sml_message, crc_error); } test/src/sml_number_test.c000066400000000000000000000111521455045705600162050ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "../unity/unity.h" #include "test_helper.h" #include TEST_GROUP(sml_number); static sml_buffer *buf; TEST_SETUP(sml_number) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_number) { sml_buffer_free(buf); } TEST(sml_number, init_unsigned8) { u8 *n = sml_u8_init(1); TEST_ASSERT_NOT_NULL(n); TEST_ASSERT_EQUAL(1, *n); sml_u8_free( n ); } TEST(sml_number, init_integer16) { i16 *n = sml_i16_init(-1); TEST_ASSERT_NOT_NULL(n); TEST_ASSERT_EQUAL(-1, *n); sml_i16_free( n ); } TEST(sml_number, parse_unsigned8) { hex2binary("6201", sml_buf_get_current_buf(buf)); u8 *n = sml_u8_parse(buf); TEST_ASSERT_EQUAL(1, *n); TEST_ASSERT_EQUAL(2, buf->cursor); sml_u8_free( n ); } TEST(sml_number, parse_unsigned16) { hex2binary("630101", sml_buf_get_current_buf(buf)); u16 *n = sml_u16_parse(buf); TEST_ASSERT_EQUAL(257, *n); sml_u16_free( n ); } TEST(sml_number, parse_unsigned32) { hex2binary("6500000001", sml_buf_get_current_buf(buf)); u32 *n = sml_u32_parse(buf); TEST_ASSERT_EQUAL(1, *n); sml_u32_free( n ); } TEST(sml_number, parse_unsigned32_fewer_bytes) { hex2binary("64010001", sml_buf_get_current_buf(buf)); u32 *n = sml_u32_parse(buf); TEST_ASSERT_EQUAL(65537, *n); sml_u32_free( n ); } TEST(sml_number, parse_unsigned32_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); u32 *n = sml_u32_parse(buf); TEST_ASSERT_NULL(n); TEST_ASSERT_EQUAL(1, buf->cursor); sml_u32_free( n ); } TEST(sml_number, parse_unsigned64) { hex2binary("690000000000000001", sml_buf_get_current_buf(buf)); u64 *n = sml_u64_parse(buf); TEST_ASSERT_EQUAL(1, *n); sml_u64_free( n ); } TEST(sml_number, parse_unsigned64_fewer_bytes) { hex2binary("67000000000001", sml_buf_get_current_buf(buf)); u64 *n = sml_u64_parse(buf); TEST_ASSERT_EQUAL(1, *n); sml_u64_free( n ); } TEST(sml_number, parse_int8) { hex2binary("52FF", sml_buf_get_current_buf(buf)); i8 *n = sml_i8_parse(buf); TEST_ASSERT_EQUAL(-1, *n); sml_i8_free( n ); } TEST(sml_number, parse_int16) { hex2binary("53EC78", sml_buf_get_current_buf(buf)); i16 *n = sml_i16_parse(buf); TEST_ASSERT_EQUAL(-5000, *n); sml_i16_free( n ); } TEST(sml_number, parse_int32) { hex2binary("55FFFFEC78", sml_buf_get_current_buf(buf)); i32 *n = sml_i32_parse(buf); TEST_ASSERT_EQUAL(-5000, *n); sml_i32_free( n ); } TEST(sml_number, parse_int64) { hex2binary("59FFFFFFFFFFFFFFFF", sml_buf_get_current_buf(buf)); i64 *n = sml_i64_parse(buf); TEST_ASSERT_EQUAL(-1, *n); sml_i64_free( n ); } TEST(sml_number, parse_int64_fewer_bytes) { hex2binary("58FFFFFFFFFFEC78", sml_buf_get_current_buf(buf)); i64 *n = sml_i64_parse(buf); TEST_ASSERT_EQUAL(-5000, *n); sml_i64_free( n ); } TEST(sml_number, write_unsigned8) { u8 *n = sml_u8_init(1); sml_u8_write(n, buf); expected_buf(buf, "6201", 2); sml_u8_free( n ); } TEST(sml_number, write_integer32) { i32 *n = sml_i32_init(-5000); sml_i32_write(n, buf); expected_buf(buf, "55FFFFEC78", 5); sml_i32_free( n ); } TEST(sml_number, write_integer8_optional) { sml_i8_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_number) { RUN_TEST_CASE(sml_number, init_unsigned8); RUN_TEST_CASE(sml_number, init_integer16); RUN_TEST_CASE(sml_number, parse_unsigned8); RUN_TEST_CASE(sml_number, parse_unsigned16); RUN_TEST_CASE(sml_number, parse_unsigned32); RUN_TEST_CASE(sml_number, parse_unsigned64); RUN_TEST_CASE(sml_number, parse_unsigned32_fewer_bytes); RUN_TEST_CASE(sml_number, parse_unsigned64_fewer_bytes); RUN_TEST_CASE(sml_number, parse_unsigned32_optional); RUN_TEST_CASE(sml_number, parse_int8); RUN_TEST_CASE(sml_number, parse_int16); RUN_TEST_CASE(sml_number, parse_int32); RUN_TEST_CASE(sml_number, parse_int64); RUN_TEST_CASE(sml_number, parse_int64_fewer_bytes); RUN_TEST_CASE(sml_number, write_unsigned8); RUN_TEST_CASE(sml_number, write_integer32); RUN_TEST_CASE(sml_number, write_integer8_optional); } test/src/sml_octet_string_test.c000066400000000000000000000072251455045705600174270ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_octet_string); static sml_buffer *buf; TEST_SETUP(sml_octet_string) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_octet_string) { sml_buffer_free(buf); } TEST(sml_octet_string, init) { octet_string *str = sml_octet_string_init((unsigned char *)"hallo", 5); TEST_ASSERT_EQUAL(5, str->len); TEST_ASSERT_EQUAL_MEMORY("hallo", str->str, 5); sml_octet_string_free( str ); } TEST(sml_octet_string, parse) { hex2binary("0648616C6C6F", sml_buf_get_current_buf(buf)); octet_string *str = sml_octet_string_parse(buf); expected_octet_string(str, "Hallo", 5); sml_octet_string_free( str ); } TEST(sml_octet_string, parse_multiple_tl_fields) { hex2binary("8102616161616F6161616161616161616161", sml_buf_get_current_buf(buf)); octet_string *str = sml_octet_string_parse(buf); expected_octet_string(str, "aaaaoaaaaaaaaaaa", 16); sml_octet_string_free( str ); } TEST(sml_octet_string, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); octet_string *str = sml_octet_string_parse(buf); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); TEST_ASSERT_NULL(str); TEST_ASSERT_EQUAL(1, buf->cursor); sml_octet_string_free( str ); } TEST(sml_octet_string, write) { octet_string *str = sml_octet_string_init((unsigned char *)"Hallo", 5); sml_octet_string_write(str, buf); expected_buf(buf, "0648616C6C6F", 6); sml_octet_string_free( str ); } TEST(sml_octet_string, write_multiple_tl_fields) { octet_string *str = sml_octet_string_init((unsigned char *)"aaaaoaaaaaaaaaaa", 16); sml_octet_string_write(str, buf); expected_buf(buf, "8102616161616F6161616161616161616161", 18); sml_octet_string_free( str ); } TEST(sml_octet_string, write_optional) { sml_octet_string_write(0, buf); expected_buf(buf, "01", 1); } TEST(sml_octet_string, cmp) { octet_string *s1 = sml_octet_string_init((unsigned char *)"Hallo", 5); octet_string *s2 = sml_octet_string_init((unsigned char *)"Hi", 2); octet_string *s3 = sml_octet_string_init((unsigned char *)"Hallo", 5); TEST_ASSERT_TRUE(sml_octet_string_cmp(s1, s2) != 0); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp(s1, s3)); sml_octet_string_free( s3 ); sml_octet_string_free( s2 ); sml_octet_string_free( s1 ); } TEST(sml_octet_string, cmp_with_hex) { octet_string *s = sml_octet_string_init((unsigned char *)"Hallo", 5); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(s, "48616C6C6F")); sml_octet_string_free( s ); } TEST_GROUP_RUNNER(sml_octet_string) { RUN_TEST_CASE(sml_octet_string, init); RUN_TEST_CASE(sml_octet_string, parse); RUN_TEST_CASE(sml_octet_string, parse_multiple_tl_fields); RUN_TEST_CASE(sml_octet_string, parse_optional); RUN_TEST_CASE(sml_octet_string, write); RUN_TEST_CASE(sml_octet_string, write_multiple_tl_fields); RUN_TEST_CASE(sml_octet_string, write_optional); RUN_TEST_CASE(sml_octet_string, cmp); RUN_TEST_CASE(sml_octet_string, cmp_with_hex); } test/src/sml_open_request_test.c000066400000000000000000000023351455045705600174310ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_open_request); static sml_buffer *buf; TEST_SETUP(sml_open_request) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_open_request) { sml_buffer_free(buf); } TEST(sml_open_request, init) { sml_open_request *m = sml_open_request_init(); TEST_ASSERT_NOT_NULL(m); sml_open_request_free( m ); } TEST_GROUP_RUNNER(sml_open_request) { RUN_TEST_CASE(sml_open_request, init); } test/src/sml_status_test.c000066400000000000000000000047361455045705600162520ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_status); static sml_buffer *buf; TEST_SETUP(sml_status) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_status) { sml_buffer_free(buf); } TEST(sml_status, init) { sml_status *s = sml_status_init(); TEST_ASSERT_NOT_NULL(s); sml_status_free( s ); } TEST(sml_status, parse_status8) { hex2binary("6201", sml_buf_get_current_buf(buf)); sml_status *s = sml_status_parse(buf); TEST_ASSERT_NOT_NULL(s); TEST_ASSERT_EQUAL(1, *(s->data.status8)); TEST_ASSERT_EQUAL((SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_8), s->type); sml_status_free( s ); } TEST(sml_status, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_status *s = sml_status_parse(buf); TEST_ASSERT_NULL(s); TEST_ASSERT_FALSE(sml_buf_has_errors(buf)); TEST_ASSERT_EQUAL(1, buf->cursor); sml_status_free( s ); } TEST(sml_status, parse_not_unsigned) { hex2binary("5001", sml_buf_get_current_buf(buf)); sml_status *s = sml_status_parse(buf); TEST_ASSERT_NULL(s); TEST_ASSERT_TRUE(sml_buf_has_errors(buf)); sml_status_free( s ); } TEST(sml_status, write_status32) { sml_status *s = sml_status_init(); s->type = SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32; s->data.status32 = sml_u32_init(42); sml_status_write(s, buf); expected_buf(buf, "650000002A", 5); sml_status_free( s ); } TEST(sml_status, write_optional) { sml_status_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_status) { RUN_TEST_CASE(sml_status, init); RUN_TEST_CASE(sml_status, parse_status8); RUN_TEST_CASE(sml_status, parse_optional); RUN_TEST_CASE(sml_status, parse_not_unsigned); RUN_TEST_CASE(sml_status, write_status32); RUN_TEST_CASE(sml_status, write_optional); } test/src/sml_time_test.c000066400000000000000000000046311455045705600156570ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_time); static sml_buffer *buf; TEST_SETUP(sml_time) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_time) { sml_buffer_free(buf); } TEST(sml_time, init) { sml_time *t = sml_time_init(); TEST_ASSERT_NOT_NULL(t); sml_time_free( t ); } TEST(sml_time, parse_sec_index) { hex2binary("72620165000000FF", sml_buf_get_current_buf(buf)); sml_time *t = sml_time_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(SML_TIME_SEC_INDEX, *(t->tag)); TEST_ASSERT_EQUAL(8, buf->cursor); sml_time_free( t ); } TEST(sml_time, parse_timestamp) { hex2binary("72620265000000FF", sml_buf_get_current_buf(buf)); sml_time *t = sml_time_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(SML_TIME_TIMESTAMP, *(t->tag)); TEST_ASSERT_EQUAL(8, buf->cursor); sml_time_free( t ); } TEST(sml_time, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_time *t = sml_time_parse(buf); TEST_ASSERT_NULL(t); TEST_ASSERT_EQUAL(1, buf->cursor); sml_time_free( t ); } TEST(sml_time, write_sec_index) { sml_time *t = sml_time_init(); t->data.sec_index = sml_u32_init(255); t->tag = sml_u8_init(SML_TIME_SEC_INDEX); sml_time_write(t, buf); expected_buf(buf, "72620165000000FF", 8); sml_time_free( t ); } TEST(sml_time, write_optional) { sml_time_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_time) { RUN_TEST_CASE(sml_time, init); RUN_TEST_CASE(sml_time, parse_sec_index); RUN_TEST_CASE(sml_time, parse_timestamp); RUN_TEST_CASE(sml_time, parse_optional); RUN_TEST_CASE(sml_time, write_sec_index); RUN_TEST_CASE(sml_time, write_optional); } test/src/sml_tree_test.c000066400000000000000000000116561455045705600156650ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include #include TEST_GROUP(sml_tree); static sml_buffer *buf; TEST_SETUP(sml_tree) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_tree) { sml_buffer_free(buf); } TEST(sml_tree, init) { sml_tree *t = sml_tree_init(); TEST_ASSERT_NOT_NULL(t); sml_tree_free( t ); } TEST(sml_tree, add_tree) { sml_tree *t = sml_tree_init(); sml_tree_add_tree(t, sml_tree_init()); TEST_ASSERT_NOT_NULL(t->child_list[0]); TEST_ASSERT_EQUAL(1, t->child_list_len); sml_tree_free( t ); } TEST(sml_tree, write) { sml_tree *t = sml_tree_init(); t->parameter_name = sml_octet_string_init((unsigned char *)"Hallo", 5); sml_tree_write(t, buf); expected_buf(buf, "730648616C6C6F0101", 9); sml_tree_free( t ); } TEST(sml_tree, parse_with_child) { hex2binary("730648616C6C6F0171730648616C6C6F0101", sml_buf_get_current_buf(buf)); sml_tree *t = sml_tree_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_NOT_NULL(t->child_list[0]); TEST_ASSERT_EQUAL(1, t->child_list_len); sml_tree_free( t ); } TEST(sml_tree, parse_with_error_child) { hex2binary("730648616C6C6F0171720648616C6C6F0101", sml_buf_get_current_buf(buf)); sml_tree *t = sml_tree_parse(buf); TEST_ASSERT_NULL(t); sml_tree_free( t ); } TEST_GROUP_RUNNER(sml_tree) { RUN_TEST_CASE(sml_tree, init); RUN_TEST_CASE(sml_tree, add_tree); RUN_TEST_CASE(sml_tree, write); RUN_TEST_CASE(sml_tree, parse_with_child); RUN_TEST_CASE(sml_tree, parse_with_error_child); } TEST_GROUP(sml_tree_path); TEST_SETUP(sml_tree_path) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_tree_path) { sml_buffer_free(buf); } TEST(sml_tree_path, init) { sml_tree_path *t = sml_tree_path_init(); TEST_ASSERT_NOT_NULL(t); sml_tree_path_free( t ); } TEST(sml_tree_path, add_entry) { sml_tree_path *t = sml_tree_path_init(); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(0, t->path_entries_len); sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"tree", 4)); TEST_ASSERT_EQUAL(1, t->path_entries_len); sml_tree_path_free( t ); } TEST(sml_tree_path, parse) { hex2binary("720648616C6C6F0264", sml_buf_get_current_buf(buf)); sml_tree_path *t = sml_tree_path_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(2, t->path_entries_len); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(t->path_entries[0], "48616C6C6F")); TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(t->path_entries[1], "64")); sml_tree_path_free( t ); } TEST(sml_tree_path, write) { sml_tree_path *t = sml_tree_path_init(); sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"Hallo", 5)); sml_tree_path_write(t, buf); expected_buf(buf, "720648616C6C6F0648616C6C6F", 13); sml_tree_path_free( t ); } TEST_GROUP_RUNNER(sml_tree_path) { RUN_TEST_CASE(sml_tree_path, init); RUN_TEST_CASE(sml_tree_path, add_entry); RUN_TEST_CASE(sml_tree_path, parse); RUN_TEST_CASE(sml_tree_path, write); } TEST_GROUP(sml_proc_par_value); TEST_SETUP(sml_proc_par_value) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_proc_par_value) { sml_buffer_free(buf); } TEST(sml_proc_par_value, init) { sml_proc_par_value *t = sml_proc_par_value_init(); TEST_ASSERT_NOT_NULL(t); sml_proc_par_value_free( t ); } TEST(sml_proc_par_value, parse_time) { hex2binary("72620472620265000000FF", sml_buf_get_current_buf(buf)); sml_proc_par_value *t = sml_proc_par_value_parse(buf); TEST_ASSERT_NOT_NULL(t); TEST_ASSERT_EQUAL(SML_PROC_PAR_VALUE_TAG_TIME, *(t->tag)); TEST_ASSERT_EQUAL(11, buf->cursor); sml_proc_par_value_free( t ); } TEST(sml_proc_par_value, write_time) { sml_proc_par_value *ppv = sml_proc_par_value_init(); ppv->tag = sml_u8_init(SML_PROC_PAR_VALUE_TAG_TIME); sml_time *t = sml_time_init(); t->data.sec_index = sml_u32_init(255); t->tag = sml_u8_init(SML_TIME_SEC_INDEX); ppv->data.time = t; sml_proc_par_value_write(ppv, buf); expected_buf(buf, "72620472620165000000FF", 11); sml_proc_par_value_free( ppv ); } TEST_GROUP_RUNNER(sml_proc_par_value) { RUN_TEST_CASE(sml_proc_par_value, init); RUN_TEST_CASE(sml_proc_par_value, parse_time); RUN_TEST_CASE(sml_proc_par_value, write_time); } test/src/sml_value_test.c000066400000000000000000000077741455045705600160500ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "../unity/unity_fixture.h" #include "test_helper.h" #include TEST_GROUP(sml_value); static sml_buffer *buf; TEST_SETUP(sml_value) { buf = sml_buffer_init(512); } TEST_TEAR_DOWN(sml_value) { sml_buffer_free(buf); } TEST(sml_value, init) { sml_value *v = sml_value_init(); TEST_ASSERT_NOT_NULL(v); sml_value_free( v ); } TEST(sml_value, parse_octet_string) { hex2binary("0648616C6C6F", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_NOT_NULL(v); TEST_ASSERT_EQUAL(SML_TYPE_OCTET_STRING, v->type); expected_octet_string(v->data.bytes, "Hallo", 5); sml_value_free( v ); } TEST(sml_value, parse_boolean) { hex2binary("4200", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_NOT_NULL(v); TEST_ASSERT_EQUAL(SML_TYPE_BOOLEAN, v->type); TEST_ASSERT_FALSE(*(v->data.boolean)); sml_value_free( v ); } TEST(sml_value, parse_unsigned32) { hex2binary("6500000001", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_NOT_NULL(v); TEST_ASSERT_EQUAL(1, *(v->data.uint32)); TEST_ASSERT_EQUAL((SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32), v->type); TEST_ASSERT_EQUAL(5, buf->cursor); sml_value_free( v ); } TEST(sml_value, parse_integer64_fewer_bytes) { hex2binary("58FFFFFFFFFFFF0F", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_EQUAL(-241, *(v->data.int64)); TEST_ASSERT_EQUAL((SML_TYPE_INTEGER | SML_TYPE_NUMBER_64), v->type); sml_value_free( v ); } TEST(sml_value, parse_optional) { hex2binary("01", sml_buf_get_current_buf(buf)); sml_value *v = sml_value_parse(buf); TEST_ASSERT_NULL(v); TEST_ASSERT_EQUAL(1, buf->cursor); sml_value_free( v ); } TEST(sml_value, write_octet_string) { sml_value *v = sml_value_init(); v->type = SML_TYPE_OCTET_STRING; v->data.bytes = sml_octet_string_init((unsigned char *)"Hallo", 5); sml_value_write(v, buf); expected_buf(buf, "0648616C6C6F", 6); sml_value_free( v ); } TEST(sml_value, write_boolean) { sml_value *v = sml_value_init(); v->type = SML_TYPE_BOOLEAN; v->data.boolean = sml_boolean_init(SML_BOOLEAN_FALSE); sml_value_write(v, buf); expected_buf(buf, "4200", 2); sml_value_free( v ); } TEST(sml_value, write_unsigned32) { sml_value *v = sml_value_init(); v->type = SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32; v->data.uint32 = sml_u32_init(42); sml_value_write(v, buf); expected_buf(buf, "650000002A", 5); sml_value_free( v ); } TEST(sml_value, write_integer16) { sml_value *v = sml_value_init(); v->type = SML_TYPE_INTEGER | SML_TYPE_NUMBER_16; v->data.int16 = sml_i16_init(-5); sml_value_write(v, buf); expected_buf(buf, "53FFFB", 3); sml_value_free( v ); } TEST(sml_value, write_optional) { sml_value_write(0, buf); expected_buf(buf, "01", 1); } TEST_GROUP_RUNNER(sml_value) { RUN_TEST_CASE(sml_value, init); RUN_TEST_CASE(sml_value, parse_octet_string); RUN_TEST_CASE(sml_value, parse_boolean); RUN_TEST_CASE(sml_value, parse_unsigned32); RUN_TEST_CASE(sml_value, parse_integer64_fewer_bytes); RUN_TEST_CASE(sml_value, parse_optional); RUN_TEST_CASE(sml_value, write_octet_string); RUN_TEST_CASE(sml_value, write_boolean); RUN_TEST_CASE(sml_value, write_unsigned32); RUN_TEST_CASE(sml_value, write_integer16); RUN_TEST_CASE(sml_value, write_optional); } test/src/test_helper.c000066400000000000000000000037731455045705600153330ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "test_helper.h" #include "../unity/unity_fixture.h" #include #include uint8_t test_helper_ctoi(uint8_t c){ uint8_t ret = 0; if((c >= '0') && (c <= '9')){ ret = c - '0'; } else if((c >= 'a') && (c <= 'f')){ ret = c - 'a' + 10; } else if((c >= 'A') && (c <= 'F')){ ret = c - 'A' + 10; } return ret; } // fix compiler warning - uncomment if needed // static inline uint8_t test_helper_c2toi(uint8_t c1, uint8_t c2){ // return test_helper_ctoi(c1) << 4 | test_helper_ctoi(c2); // } static inline uint8_t test_helper_c2ptoi(char* c){ return test_helper_ctoi((uint8_t)c[0]) << 4 | test_helper_ctoi((uint8_t)c[1]); } int hex2binary(char *hex, unsigned char *buf) { int i; int len = strlen(hex); for (i = 0; i < (len /2); i++) { buf[i] = test_helper_c2ptoi(&(hex[i * 2])); } return i; } void expected_buf(sml_buffer *buf, char *hex, int len) { unsigned char expected_buf[len]; hex2binary(hex, expected_buf); TEST_ASSERT_EQUAL_MEMORY(expected_buf, buf->buffer, len); TEST_ASSERT_EQUAL(len, buf->cursor); } void expected_octet_string(octet_string *str, char *content, int len) { TEST_ASSERT_NOT_NULL(str); TEST_ASSERT_EQUAL(len, str->len); TEST_ASSERT_EQUAL_MEMORY(content, str->str, len); } test/src/test_helper.h000066400000000000000000000020231455045705600153230ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #ifndef TEST_HELPER_H_ #define TEST_HELPER_H_ #include #include int hex2binary(char *hex, unsigned char *buf); void expected_buf(sml_buffer *buf, char *hex, int len); void expected_octet_string(octet_string *str, char *content, int len); #endif test/test_main.c000066400000000000000000000025661455045705600142100ustar00rootroot00000000000000// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed // DAI-Labor, TU-Berlin // // This file is part of libSML. // // libSML 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 3 of the License, or // (at your option) any later version. // // libSML 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 libSML. If not, see . #include "unity/unity_fixture.h" static void runAllTests() { RUN_TEST_GROUP(sml_octet_string); RUN_TEST_GROUP(sml_buffer); RUN_TEST_GROUP(sml_number); RUN_TEST_GROUP(sml_boolean); RUN_TEST_GROUP(sml_value); RUN_TEST_GROUP(sml_status); RUN_TEST_GROUP(sml_list); RUN_TEST_GROUP(sml_sequence); RUN_TEST_GROUP(sml_time); RUN_TEST_GROUP(sml_tree); RUN_TEST_GROUP(sml_tree_path); RUN_TEST_GROUP(sml_proc_par_value); RUN_TEST_GROUP(sml_open_request); RUN_TEST_GROUP(sml_get_profile_pack_request); RUN_TEST_GROUP(sml_message); RUN_TEST_GROUP(sml_file); } int main(int argc, char * argv[]) { return UnityMain(argc, argv, runAllTests); } test/unity/000077500000000000000000000000001455045705600132205ustar00rootroot00000000000000test/unity/license.txt000066400000000000000000000031251455045705600154040ustar00rootroot00000000000000 Copyright (c) 2007-2010 Mike Karlesky, Mark VanderVoord, Greg Williams Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed for the Unity Project, by Mike Karlesky, Mark VanderVoord, and Greg Williams and other contributors", in the same place and form as other third-party acknowledgments. Alternately, this acknowledgment may appear in the software itself, in the same form and location as other such third-party acknowledgments. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.test/unity/unity.c000066400000000000000000001777161455045705600145570ustar00rootroot00000000000000/* ========================================================================= Unity Project - A Test Framework for C Copyright (c) 2007-21 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ============================================================================ */ #include "unity.h" #include #ifdef AVR #include #else #define PROGMEM #endif /* If omitted from header, declare overrideable prototypes here so they're ready for use */ #ifdef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION void UNITY_OUTPUT_CHAR(int); #endif /* Helpful macros for us to use here in Assert functions */ #define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); } #define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); } #define RETURN_IF_FAIL_OR_IGNORE if (Unity.CurrentTestFailed || Unity.CurrentTestIgnored) TEST_ABORT() struct UNITY_STORAGE_T Unity; #ifdef UNITY_OUTPUT_COLOR const char PROGMEM UnityStrOk[] = "\033[42mOK\033[00m"; const char PROGMEM UnityStrPass[] = "\033[42mPASS\033[00m"; const char PROGMEM UnityStrFail[] = "\033[41mFAIL\033[00m"; const char PROGMEM UnityStrIgnore[] = "\033[43mIGNORE\033[00m"; #else const char PROGMEM UnityStrOk[] = "OK"; const char PROGMEM UnityStrPass[] = "PASS"; const char PROGMEM UnityStrFail[] = "FAIL"; const char PROGMEM UnityStrIgnore[] = "IGNORE"; #endif static const char PROGMEM UnityStrNull[] = "NULL"; static const char PROGMEM UnityStrSpacer[] = ". "; static const char PROGMEM UnityStrExpected[] = " Expected "; static const char PROGMEM UnityStrWas[] = " Was "; static const char PROGMEM UnityStrGt[] = " to be greater than "; static const char PROGMEM UnityStrLt[] = " to be less than "; static const char PROGMEM UnityStrOrEqual[] = "or equal to "; static const char PROGMEM UnityStrNotEqual[] = " to be not equal to "; static const char PROGMEM UnityStrElement[] = " Element "; static const char PROGMEM UnityStrByte[] = " Byte "; static const char PROGMEM UnityStrMemory[] = " Memory Mismatch."; static const char PROGMEM UnityStrDelta[] = " Values Not Within Delta "; static const char PROGMEM UnityStrPointless[] = " You Asked Me To Compare Nothing, Which Was Pointless."; static const char PROGMEM UnityStrNullPointerForExpected[] = " Expected pointer to be NULL"; static const char PROGMEM UnityStrNullPointerForActual[] = " Actual pointer was NULL"; #ifndef UNITY_EXCLUDE_FLOAT static const char PROGMEM UnityStrNot[] = "Not "; static const char PROGMEM UnityStrInf[] = "Infinity"; static const char PROGMEM UnityStrNegInf[] = "Negative Infinity"; static const char PROGMEM UnityStrNaN[] = "NaN"; static const char PROGMEM UnityStrDet[] = "Determinate"; static const char PROGMEM UnityStrInvalidFloatTrait[] = "Invalid Float Trait"; #endif const char PROGMEM UnityStrErrShorthand[] = "Unity Shorthand Support Disabled"; const char PROGMEM UnityStrErrFloat[] = "Unity Floating Point Disabled"; const char PROGMEM UnityStrErrDouble[] = "Unity Double Precision Disabled"; const char PROGMEM UnityStrErr64[] = "Unity 64-bit Support Disabled"; static const char PROGMEM UnityStrBreaker[] = "-----------------------"; static const char PROGMEM UnityStrResultsTests[] = " Tests "; static const char PROGMEM UnityStrResultsFailures[] = " Failures "; static const char PROGMEM UnityStrResultsIgnored[] = " Ignored "; #ifndef UNITY_EXCLUDE_DETAILS static const char PROGMEM UnityStrDetail1Name[] = UNITY_DETAIL1_NAME " "; static const char PROGMEM UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " "; #endif /*----------------------------------------------- * Pretty Printers & Test Result Output Handlers *-----------------------------------------------*/ /*-----------------------------------------------*/ /* Local helper function to print characters. */ static void UnityPrintChar(const char* pch) { /* printable characters plus CR & LF are printed */ if ((*pch <= 126) && (*pch >= 32)) { UNITY_OUTPUT_CHAR(*pch); } /* write escaped carriage returns */ else if (*pch == 13) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('r'); } /* write escaped line feeds */ else if (*pch == 10) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('n'); } /* unprintable characters are shown as codes */ else { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('x'); UnityPrintNumberHex((UNITY_UINT)*pch, 2); } } /*-----------------------------------------------*/ /* Local helper function to print ANSI escape strings e.g. "\033[42m". */ #ifdef UNITY_OUTPUT_COLOR static UNITY_UINT UnityPrintAnsiEscapeString(const char* string) { const char* pch = string; UNITY_UINT count = 0; while (*pch && (*pch != 'm')) { UNITY_OUTPUT_CHAR(*pch); pch++; count++; } UNITY_OUTPUT_CHAR('m'); count++; return count; } #endif /*-----------------------------------------------*/ void UnityPrint(const char* string) { const char* pch = string; if (pch != NULL) { while (*pch) { #ifdef UNITY_OUTPUT_COLOR /* print ANSI escape code */ if ((*pch == 27) && (*(pch + 1) == '[')) { pch += UnityPrintAnsiEscapeString(pch); continue; } #endif UnityPrintChar(pch); pch++; } } } /*-----------------------------------------------*/ void UnityPrintLen(const char* string, const UNITY_UINT32 length) { const char* pch = string; if (pch != NULL) { while (*pch && ((UNITY_UINT32)(pch - string) < length)) { /* printable characters plus CR & LF are printed */ if ((*pch <= 126) && (*pch >= 32)) { UNITY_OUTPUT_CHAR(*pch); } /* write escaped carriage returns */ else if (*pch == 13) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('r'); } /* write escaped line feeds */ else if (*pch == 10) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('n'); } /* unprintable characters are shown as codes */ else { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('x'); UnityPrintNumberHex((UNITY_UINT)*pch, 2); } pch++; } } } /*-----------------------------------------------*/ void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style) { if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { if (style == UNITY_DISPLAY_STYLE_CHAR) { /* printable characters plus CR & LF are printed */ UNITY_OUTPUT_CHAR('\''); if ((number <= 126) && (number >= 32)) { UNITY_OUTPUT_CHAR((int)number); } /* write escaped carriage returns */ else if (number == 13) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('r'); } /* write escaped line feeds */ else if (number == 10) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('n'); } /* unprintable characters are shown as codes */ else { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('x'); UnityPrintNumberHex((UNITY_UINT)number, 2); } UNITY_OUTPUT_CHAR('\''); } else { UnityPrintNumber(number); } } else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) { UnityPrintNumberUnsigned((UNITY_UINT)number); } else { UNITY_OUTPUT_CHAR('0'); UNITY_OUTPUT_CHAR('x'); UnityPrintNumberHex((UNITY_UINT)number, (char)((style & 0xF) * 2)); } } /*-----------------------------------------------*/ void UnityPrintNumber(const UNITY_INT number_to_print) { UNITY_UINT number = (UNITY_UINT)number_to_print; if (number_to_print < 0) { /* A negative number, including MIN negative */ UNITY_OUTPUT_CHAR('-'); number = (~number) + 1; } UnityPrintNumberUnsigned(number); } /*----------------------------------------------- * basically do an itoa using as little ram as possible */ void UnityPrintNumberUnsigned(const UNITY_UINT number) { UNITY_UINT divisor = 1; /* figure out initial divisor */ while (number / divisor > 9) { divisor *= 10; } /* now mod and print, then divide divisor */ do { UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10))); divisor /= 10; } while (divisor > 0); } /*-----------------------------------------------*/ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) { int nibble; char nibbles = nibbles_to_print; if ((unsigned)nibbles > UNITY_MAX_NIBBLES) { nibbles = UNITY_MAX_NIBBLES; } while (nibbles > 0) { nibbles--; nibble = (int)(number >> (nibbles * 4)) & 0x0F; if (nibble <= 9) { UNITY_OUTPUT_CHAR((char)('0' + nibble)); } else { UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble)); } } } /*-----------------------------------------------*/ void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number) { UNITY_UINT current_bit = (UNITY_UINT)1 << (UNITY_INT_WIDTH - 1); UNITY_INT32 i; for (i = 0; i < UNITY_INT_WIDTH; i++) { if (current_bit & mask) { if (current_bit & number) { UNITY_OUTPUT_CHAR('1'); } else { UNITY_OUTPUT_CHAR('0'); } } else { UNITY_OUTPUT_CHAR('X'); } current_bit = current_bit >> 1; } } /*-----------------------------------------------*/ #ifndef UNITY_EXCLUDE_FLOAT_PRINT /* * This function prints a floating-point value in a format similar to * printf("%.7g") on a single-precision machine or printf("%.9g") on a * double-precision machine. The 7th digit won't always be totally correct * in single-precision operation (for that level of accuracy, a more * complicated algorithm would be needed). */ void UnityPrintFloat(const UNITY_DOUBLE input_number) { #ifdef UNITY_INCLUDE_DOUBLE static const int sig_digits = 9; static const UNITY_INT32 min_scaled = 100000000; static const UNITY_INT32 max_scaled = 1000000000; #else static const int sig_digits = 7; static const UNITY_INT32 min_scaled = 1000000; static const UNITY_INT32 max_scaled = 10000000; #endif UNITY_DOUBLE number = input_number; /* print minus sign (does not handle negative zero) */ if (number < 0.0f) { UNITY_OUTPUT_CHAR('-'); number = -number; } /* handle zero, NaN, and +/- infinity */ if (number == 0.0f) { UnityPrint("0"); } else if (isnan(number)) { UnityPrint("nan"); } else if (isinf(number)) { UnityPrint("inf"); } else { UNITY_INT32 n_int = 0, n; int exponent = 0; int decimals, digits; char buf[16] = {0}; /* * Scale up or down by powers of 10. To minimize rounding error, * start with a factor/divisor of 10^10, which is the largest * power of 10 that can be represented exactly. Finally, compute * (exactly) the remaining power of 10 and perform one more * multiplication or division. */ if (number < 1.0f) { UNITY_DOUBLE factor = 1.0f; while (number < (UNITY_DOUBLE)max_scaled / 1e10f) { number *= 1e10f; exponent -= 10; } while (number * factor < (UNITY_DOUBLE)min_scaled) { factor *= 10.0f; exponent--; } number *= factor; } else if (number > (UNITY_DOUBLE)max_scaled) { UNITY_DOUBLE divisor = 1.0f; while (number > (UNITY_DOUBLE)min_scaled * 1e10f) { number /= 1e10f; exponent += 10; } while (number / divisor > (UNITY_DOUBLE)max_scaled) { divisor *= 10.0f; exponent++; } number /= divisor; } else { /* * In this range, we can split off the integer part before * doing any multiplications. This reduces rounding error by * freeing up significant bits in the fractional part. */ UNITY_DOUBLE factor = 1.0f; n_int = (UNITY_INT32)number; number -= (UNITY_DOUBLE)n_int; while (n_int < min_scaled) { n_int *= 10; factor *= 10.0f; exponent--; } number *= factor; } /* round to nearest integer */ n = ((UNITY_INT32)(number + number) + 1) / 2; #ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO /* round to even if exactly between two integers */ if ((n & 1) && (((UNITY_DOUBLE)n - number) == 0.5f)) n--; #endif n += n_int; if (n >= max_scaled) { n = min_scaled; exponent++; } /* determine where to place decimal point */ decimals = ((exponent <= 0) && (exponent >= -(sig_digits + 3))) ? (-exponent) : (sig_digits - 1); exponent += decimals; /* truncate trailing zeroes after decimal point */ while ((decimals > 0) && ((n % 10) == 0)) { n /= 10; decimals--; } /* build up buffer in reverse order */ digits = 0; while ((n != 0) || (digits < (decimals + 1))) { buf[digits++] = (char)('0' + n % 10); n /= 10; } while (digits > 0) { if (digits == decimals) { UNITY_OUTPUT_CHAR('.'); } UNITY_OUTPUT_CHAR(buf[--digits]); } /* print exponent if needed */ if (exponent != 0) { UNITY_OUTPUT_CHAR('e'); if (exponent < 0) { UNITY_OUTPUT_CHAR('-'); exponent = -exponent; } else { UNITY_OUTPUT_CHAR('+'); } digits = 0; while ((exponent != 0) || (digits < 2)) { buf[digits++] = (char)('0' + exponent % 10); exponent /= 10; } while (digits > 0) { UNITY_OUTPUT_CHAR(buf[--digits]); } } } } #endif /* ! UNITY_EXCLUDE_FLOAT_PRINT */ /*-----------------------------------------------*/ static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line) { #ifdef UNITY_OUTPUT_FOR_ECLIPSE UNITY_OUTPUT_CHAR('('); UnityPrint(file); UNITY_OUTPUT_CHAR(':'); UnityPrintNumber((UNITY_INT)line); UNITY_OUTPUT_CHAR(')'); UNITY_OUTPUT_CHAR(' '); UnityPrint(Unity.CurrentTestName); UNITY_OUTPUT_CHAR(':'); #else #ifdef UNITY_OUTPUT_FOR_IAR_WORKBENCH UnityPrint("'); UnityPrint(Unity.CurrentTestName); UnityPrint(" "); #else #ifdef UNITY_OUTPUT_FOR_QT_CREATOR UnityPrint("file://"); UnityPrint(file); UNITY_OUTPUT_CHAR(':'); UnityPrintNumber((UNITY_INT)line); UNITY_OUTPUT_CHAR(' '); UnityPrint(Unity.CurrentTestName); UNITY_OUTPUT_CHAR(':'); #else UnityPrint(file); UNITY_OUTPUT_CHAR(':'); UnityPrintNumber((UNITY_INT)line); UNITY_OUTPUT_CHAR(':'); UnityPrint(Unity.CurrentTestName); UNITY_OUTPUT_CHAR(':'); #endif #endif #endif } /*-----------------------------------------------*/ static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line) { UnityTestResultsBegin(Unity.TestFile, line); UnityPrint(UnityStrFail); UNITY_OUTPUT_CHAR(':'); } /*-----------------------------------------------*/ void UnityConcludeTest(void) { if (Unity.CurrentTestIgnored) { Unity.TestIgnores++; } else if (!Unity.CurrentTestFailed) { UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber); UnityPrint(UnityStrPass); } else { Unity.TestFailures++; } Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; UNITY_PRINT_EXEC_TIME(); UNITY_PRINT_EOL(); UNITY_FLUSH_CALL(); } /*-----------------------------------------------*/ static void UnityAddMsgIfSpecified(const char* msg) { if (msg) { UnityPrint(UnityStrSpacer); #ifdef UNITY_PRINT_TEST_CONTEXT UNITY_PRINT_TEST_CONTEXT(); #endif #ifndef UNITY_EXCLUDE_DETAILS if (Unity.CurrentDetail1) { UnityPrint(UnityStrDetail1Name); UnityPrint(Unity.CurrentDetail1); if (Unity.CurrentDetail2) { UnityPrint(UnityStrDetail2Name); UnityPrint(Unity.CurrentDetail2); } UnityPrint(UnityStrSpacer); } #endif UnityPrint(msg); } } /*-----------------------------------------------*/ static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual) { UnityPrint(UnityStrExpected); if (expected != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrint(expected); UNITY_OUTPUT_CHAR('\''); } else { UnityPrint(UnityStrNull); } UnityPrint(UnityStrWas); if (actual != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrint(actual); UNITY_OUTPUT_CHAR('\''); } else { UnityPrint(UnityStrNull); } } /*-----------------------------------------------*/ static void UnityPrintExpectedAndActualStringsLen(const char* expected, const char* actual, const UNITY_UINT32 length) { UnityPrint(UnityStrExpected); if (expected != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrintLen(expected, length); UNITY_OUTPUT_CHAR('\''); } else { UnityPrint(UnityStrNull); } UnityPrint(UnityStrWas); if (actual != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrintLen(actual, length); UNITY_OUTPUT_CHAR('\''); } else { UnityPrint(UnityStrNull); } } /*----------------------------------------------- * Assertion & Control Helpers *-----------------------------------------------*/ /*-----------------------------------------------*/ static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_LINE_TYPE lineNumber, const char* msg) { /* Both are NULL or same pointer */ if (expected == actual) { return 0; } /* print and return true if just expected is NULL */ if (expected == NULL) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrNullPointerForExpected); UnityAddMsgIfSpecified(msg); return 1; } /* print and return true if just actual is NULL */ if (actual == NULL) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrNullPointerForActual); UnityAddMsgIfSpecified(msg); return 1; } return 0; /* return false if neither is NULL */ } /*----------------------------------------------- * Assertion Functions *-----------------------------------------------*/ /*-----------------------------------------------*/ void UnityAssertBits(const UNITY_INT mask, const UNITY_INT expected, const UNITY_INT actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { RETURN_IF_FAIL_OR_IGNORE; if ((mask & expected) != (mask & actual)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)expected); UnityPrint(UnityStrWas); UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)actual); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } /*-----------------------------------------------*/ void UnityAssertEqualNumber(const UNITY_INT expected, const UNITY_INT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style) { RETURN_IF_FAIL_OR_IGNORE; if (expected != actual) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(expected, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(actual, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } /*-----------------------------------------------*/ void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold, const UNITY_INT actual, const UNITY_COMPARISON_T compare, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style) { int failed = 0; RETURN_IF_FAIL_OR_IGNORE; if ((threshold == actual) && (compare & UNITY_EQUAL_TO)) { return; } if ((threshold == actual)) { failed = 1; } if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { if ((actual > threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; } if ((actual < threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; } } else /* UINT or HEX */ { if (((UNITY_UINT)actual > (UNITY_UINT)threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; } if (((UNITY_UINT)actual < (UNITY_UINT)threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; } } if (failed) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(actual, style); if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); } if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); } if (compare & UNITY_EQUAL_TO) { UnityPrint(UnityStrOrEqual); } if (compare == UNITY_NOT_EQUAL) { UnityPrint(UnityStrNotEqual); } UnityPrintNumberByStyle(threshold, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } #define UnityPrintPointlessAndBail() \ { \ UnityTestResultsFailBegin(lineNumber); \ UnityPrint(UnityStrPointless); \ UnityAddMsgIfSpecified(msg); \ UNITY_FAIL_AND_BAIL; } /*-----------------------------------------------*/ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style, const UNITY_FLAGS_T flags) { UNITY_UINT32 elements = num_elements; unsigned int length = style & 0xF; unsigned int increment = 0; RETURN_IF_FAIL_OR_IGNORE; if (num_elements == 0) { UnityPrintPointlessAndBail(); } if (expected == actual) { return; /* Both are NULL or same pointer */ } if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) { UNITY_FAIL_AND_BAIL; } while ((elements > 0) && (elements--)) { UNITY_INT expect_val; UNITY_INT actual_val; switch (length) { case 1: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual; increment = sizeof(UNITY_INT8); break; case 2: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual; increment = sizeof(UNITY_INT16); break; #ifdef UNITY_SUPPORT_64 case 8: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual; increment = sizeof(UNITY_INT64); break; #endif default: /* default is length 4 bytes */ case 4: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual; increment = sizeof(UNITY_INT32); length = 4; break; } if (expect_val != actual_val) { if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < (UNITY_INT_WIDTH / 8))) { /* For UINT, remove sign extension (padding 1's) from signed type casts above */ UNITY_INT mask = 1; mask = (mask << 8 * length) - 1; expect_val &= mask; actual_val &= mask; } UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(expect_val, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(actual_val, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } /* Walk through array by incrementing the pointers */ if (flags == UNITY_ARRAY_TO_ARRAY) { expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment); } actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment); } } /*-----------------------------------------------*/ #ifndef UNITY_EXCLUDE_FLOAT /* Wrap this define in a function with variable types as float or double */ #define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \ if (isinf(expected) && isinf(actual) && (((expected) < 0) == ((actual) < 0))) return 1; \ if (UNITY_NAN_CHECK) return 1; \ (diff) = (actual) - (expected); \ if ((diff) < 0) (diff) = -(diff); \ if ((delta) < 0) (delta) = -(delta); \ return !(isnan(diff) || isinf(diff) || ((diff) > (delta))) /* This first part of this condition will catch any NaN or Infinite values */ #ifndef UNITY_NAN_NOT_EQUAL_NAN #define UNITY_NAN_CHECK isnan(expected) && isnan(actual) #else #define UNITY_NAN_CHECK 0 #endif #ifndef UNITY_EXCLUDE_FLOAT_PRINT #define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \ { \ UnityPrint(UnityStrExpected); \ UnityPrintFloat(expected); \ UnityPrint(UnityStrWas); \ UnityPrintFloat(actual); } #else #define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \ UnityPrint(UnityStrDelta) #endif /* UNITY_EXCLUDE_FLOAT_PRINT */ /*-----------------------------------------------*/ static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual) { UNITY_FLOAT diff; UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); } /*-----------------------------------------------*/ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected, UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags) { UNITY_UINT32 elements = num_elements; UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* ptr_expected = expected; UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* ptr_actual = actual; RETURN_IF_FAIL_OR_IGNORE; if (elements == 0) { UnityPrintPointlessAndBail(); } if (expected == actual) { return; /* Both are NULL or same pointer */ } if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) { UNITY_FAIL_AND_BAIL; } while (elements--) { if (!UnityFloatsWithin(*ptr_expected * UNITY_FLOAT_PRECISION, *ptr_expected, *ptr_actual)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT((UNITY_DOUBLE)*ptr_expected, (UNITY_DOUBLE)*ptr_actual); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } if (flags == UNITY_ARRAY_TO_ARRAY) { ptr_expected++; } ptr_actual++; } } /*-----------------------------------------------*/ void UnityAssertFloatsWithin(const UNITY_FLOAT delta, const UNITY_FLOAT expected, const UNITY_FLOAT actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { RETURN_IF_FAIL_OR_IGNORE; if (!UnityFloatsWithin(delta, expected, actual)) { UnityTestResultsFailBegin(lineNumber); UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT((UNITY_DOUBLE)expected, (UNITY_DOUBLE)actual); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } /*-----------------------------------------------*/ void UnityAssertFloatSpecial(const UNITY_FLOAT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLOAT_TRAIT_T style) { const char* trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet}; UNITY_INT should_be_trait = ((UNITY_INT)style & 1); UNITY_INT is_trait = !should_be_trait; UNITY_INT trait_index = (UNITY_INT)(style >> 1); RETURN_IF_FAIL_OR_IGNORE; switch (style) { case UNITY_FLOAT_IS_INF: case UNITY_FLOAT_IS_NOT_INF: is_trait = isinf(actual) && (actual > 0); break; case UNITY_FLOAT_IS_NEG_INF: case UNITY_FLOAT_IS_NOT_NEG_INF: is_trait = isinf(actual) && (actual < 0); break; case UNITY_FLOAT_IS_NAN: case UNITY_FLOAT_IS_NOT_NAN: is_trait = isnan(actual) ? 1 : 0; break; case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */ case UNITY_FLOAT_IS_NOT_DET: is_trait = !isinf(actual) && !isnan(actual); break; default: /* including UNITY_FLOAT_INVALID_TRAIT */ trait_index = 0; trait_names[0] = UnityStrInvalidFloatTrait; break; } if (is_trait != should_be_trait) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); if (!should_be_trait) { UnityPrint(UnityStrNot); } UnityPrint(trait_names[trait_index]); UnityPrint(UnityStrWas); #ifndef UNITY_EXCLUDE_FLOAT_PRINT UnityPrintFloat((UNITY_DOUBLE)actual); #else if (should_be_trait) { UnityPrint(UnityStrNot); } UnityPrint(trait_names[trait_index]); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } #endif /* not UNITY_EXCLUDE_FLOAT */ /*-----------------------------------------------*/ #ifndef UNITY_EXCLUDE_DOUBLE static int UnityDoublesWithin(UNITY_DOUBLE delta, UNITY_DOUBLE expected, UNITY_DOUBLE actual) { UNITY_DOUBLE diff; UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); } /*-----------------------------------------------*/ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected, UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags) { UNITY_UINT32 elements = num_elements; UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* ptr_expected = expected; UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* ptr_actual = actual; RETURN_IF_FAIL_OR_IGNORE; if (elements == 0) { UnityPrintPointlessAndBail(); } if (expected == actual) { return; /* Both are NULL or same pointer */ } if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) { UNITY_FAIL_AND_BAIL; } while (elements--) { if (!UnityDoublesWithin(*ptr_expected * UNITY_DOUBLE_PRECISION, *ptr_expected, *ptr_actual)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(*ptr_expected, *ptr_actual); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } if (flags == UNITY_ARRAY_TO_ARRAY) { ptr_expected++; } ptr_actual++; } } /*-----------------------------------------------*/ void UnityAssertDoublesWithin(const UNITY_DOUBLE delta, const UNITY_DOUBLE expected, const UNITY_DOUBLE actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { RETURN_IF_FAIL_OR_IGNORE; if (!UnityDoublesWithin(delta, expected, actual)) { UnityTestResultsFailBegin(lineNumber); UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } /*-----------------------------------------------*/ void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLOAT_TRAIT_T style) { const char* trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet}; UNITY_INT should_be_trait = ((UNITY_INT)style & 1); UNITY_INT is_trait = !should_be_trait; UNITY_INT trait_index = (UNITY_INT)(style >> 1); RETURN_IF_FAIL_OR_IGNORE; switch (style) { case UNITY_FLOAT_IS_INF: case UNITY_FLOAT_IS_NOT_INF: is_trait = isinf(actual) && (actual > 0); break; case UNITY_FLOAT_IS_NEG_INF: case UNITY_FLOAT_IS_NOT_NEG_INF: is_trait = isinf(actual) && (actual < 0); break; case UNITY_FLOAT_IS_NAN: case UNITY_FLOAT_IS_NOT_NAN: is_trait = isnan(actual) ? 1 : 0; break; case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */ case UNITY_FLOAT_IS_NOT_DET: is_trait = !isinf(actual) && !isnan(actual); break; default: /* including UNITY_FLOAT_INVALID_TRAIT */ trait_index = 0; trait_names[0] = UnityStrInvalidFloatTrait; break; } if (is_trait != should_be_trait) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); if (!should_be_trait) { UnityPrint(UnityStrNot); } UnityPrint(trait_names[trait_index]); UnityPrint(UnityStrWas); #ifndef UNITY_EXCLUDE_FLOAT_PRINT UnityPrintFloat(actual); #else if (should_be_trait) { UnityPrint(UnityStrNot); } UnityPrint(trait_names[trait_index]); #endif UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } #endif /* not UNITY_EXCLUDE_DOUBLE */ /*-----------------------------------------------*/ void UnityAssertNumbersWithin(const UNITY_UINT delta, const UNITY_INT expected, const UNITY_INT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style) { RETURN_IF_FAIL_OR_IGNORE; if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { if (actual > expected) { Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta); } else { Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta); } } else { if ((UNITY_UINT)actual > (UNITY_UINT)expected) { Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta); } else { Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta); } } if (Unity.CurrentTestFailed) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrDelta); UnityPrintNumberByStyle((UNITY_INT)delta, style); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(expected, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(actual, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } /*-----------------------------------------------*/ void UnityAssertNumbersArrayWithin(const UNITY_UINT delta, UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style, const UNITY_FLAGS_T flags) { UNITY_UINT32 elements = num_elements; unsigned int length = style & 0xF; unsigned int increment = 0; RETURN_IF_FAIL_OR_IGNORE; if (num_elements == 0) { UnityPrintPointlessAndBail(); } if (expected == actual) { return; /* Both are NULL or same pointer */ } if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) { UNITY_FAIL_AND_BAIL; } while ((elements > 0) && (elements--)) { UNITY_INT expect_val; UNITY_INT actual_val; switch (length) { case 1: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual; increment = sizeof(UNITY_INT8); break; case 2: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual; increment = sizeof(UNITY_INT16); break; #ifdef UNITY_SUPPORT_64 case 8: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual; increment = sizeof(UNITY_INT64); break; #endif default: /* default is length 4 bytes */ case 4: expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual; increment = sizeof(UNITY_INT32); length = 4; break; } if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { if (actual_val > expect_val) { Unity.CurrentTestFailed = (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta); } else { Unity.CurrentTestFailed = (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta); } } else { if ((UNITY_UINT)actual_val > (UNITY_UINT)expect_val) { Unity.CurrentTestFailed = (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta); } else { Unity.CurrentTestFailed = (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta); } } if (Unity.CurrentTestFailed) { if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < (UNITY_INT_WIDTH / 8))) { /* For UINT, remove sign extension (padding 1's) from signed type casts above */ UNITY_INT mask = 1; mask = (mask << 8 * length) - 1; expect_val &= mask; actual_val &= mask; } UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrDelta); UnityPrintNumberByStyle((UNITY_INT)delta, style); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(expect_val, style); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(actual_val, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } /* Walk through array by incrementing the pointers */ if (flags == UNITY_ARRAY_TO_ARRAY) { expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment); } actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment); } } /*-----------------------------------------------*/ void UnityAssertEqualString(const char* expected, const char* actual, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_UINT32 i; RETURN_IF_FAIL_OR_IGNORE; /* if both pointers not null compare the strings */ if (expected && actual) { for (i = 0; expected[i] || actual[i]; i++) { if (expected[i] != actual[i]) { Unity.CurrentTestFailed = 1; break; } } } else { /* handle case of one pointers being null (if both null, test should pass) */ if (expected != actual) { Unity.CurrentTestFailed = 1; } } if (Unity.CurrentTestFailed) { UnityTestResultsFailBegin(lineNumber); UnityPrintExpectedAndActualStrings(expected, actual); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } /*-----------------------------------------------*/ void UnityAssertEqualStringLen(const char* expected, const char* actual, const UNITY_UINT32 length, const char* msg, const UNITY_LINE_TYPE lineNumber) { UNITY_UINT32 i; RETURN_IF_FAIL_OR_IGNORE; /* if both pointers not null compare the strings */ if (expected && actual) { for (i = 0; (i < length) && (expected[i] || actual[i]); i++) { if (expected[i] != actual[i]) { Unity.CurrentTestFailed = 1; break; } } } else { /* handle case of one pointers being null (if both null, test should pass) */ if (expected != actual) { Unity.CurrentTestFailed = 1; } } if (Unity.CurrentTestFailed) { UnityTestResultsFailBegin(lineNumber); UnityPrintExpectedAndActualStringsLen(expected, actual, length); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } /*-----------------------------------------------*/ void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected, const char** actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags) { UNITY_UINT32 i = 0; UNITY_UINT32 j = 0; const char* expd = NULL; const char* act = NULL; RETURN_IF_FAIL_OR_IGNORE; /* if no elements, it's an error */ if (num_elements == 0) { UnityPrintPointlessAndBail(); } if ((const void*)expected == (const void*)actual) { return; /* Both are NULL or same pointer */ } if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) { UNITY_FAIL_AND_BAIL; } if (flags != UNITY_ARRAY_TO_ARRAY) { expd = (const char*)expected; } do { act = actual[j]; if (flags == UNITY_ARRAY_TO_ARRAY) { expd = ((const char* const*)expected)[j]; } /* if both pointers not null compare the strings */ if (expd && act) { for (i = 0; expd[i] || act[i]; i++) { if (expd[i] != act[i]) { Unity.CurrentTestFailed = 1; break; } } } else { /* handle case of one pointers being null (if both null, test should pass) */ if (expd != act) { Unity.CurrentTestFailed = 1; } } if (Unity.CurrentTestFailed) { UnityTestResultsFailBegin(lineNumber); if (num_elements > 1) { UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(j); } UnityPrintExpectedAndActualStrings(expd, act); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } } while (++j < num_elements); } /*-----------------------------------------------*/ void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 length, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags) { UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected; UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual; UNITY_UINT32 elements = num_elements; UNITY_UINT32 bytes; RETURN_IF_FAIL_OR_IGNORE; if ((elements == 0) || (length == 0)) { UnityPrintPointlessAndBail(); } if (expected == actual) { return; /* Both are NULL or same pointer */ } if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) { UNITY_FAIL_AND_BAIL; } while (elements--) { bytes = length; while (bytes--) { if (*ptr_exp != *ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrMemory); if (num_elements > 1) { UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); } UnityPrint(UnityStrByte); UnityPrintNumberUnsigned(length - bytes - 1); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8); UnityPrint(UnityStrWas); UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } ptr_exp++; ptr_act++; } if (flags == UNITY_ARRAY_TO_VAL) { ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected; } } } /*-----------------------------------------------*/ static union { UNITY_INT8 i8; UNITY_INT16 i16; UNITY_INT32 i32; #ifdef UNITY_SUPPORT_64 UNITY_INT64 i64; #endif #ifndef UNITY_EXCLUDE_FLOAT float f; #endif #ifndef UNITY_EXCLUDE_DOUBLE double d; #endif } UnityQuickCompare; UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size) { switch(size) { case 1: UnityQuickCompare.i8 = (UNITY_INT8)num; return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i8); case 2: UnityQuickCompare.i16 = (UNITY_INT16)num; return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i16); #ifdef UNITY_SUPPORT_64 case 8: UnityQuickCompare.i64 = (UNITY_INT64)num; return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i64); #endif default: /* 4 bytes */ UnityQuickCompare.i32 = (UNITY_INT32)num; return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i32); } } #ifndef UNITY_EXCLUDE_FLOAT /*-----------------------------------------------*/ UNITY_INTERNAL_PTR UnityFloatToPtr(const float num) { UnityQuickCompare.f = num; return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.f); } #endif #ifndef UNITY_EXCLUDE_DOUBLE /*-----------------------------------------------*/ UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num) { UnityQuickCompare.d = num; return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.d); } #endif /*----------------------------------------------- * printf helper function *-----------------------------------------------*/ #ifdef UNITY_INCLUDE_PRINT_FORMATTED static void UnityPrintFVA(const char* format, va_list va) { const char* pch = format; if (pch != NULL) { while (*pch) { /* format identification character */ if (*pch == '%') { pch++; if (pch != NULL) { switch (*pch) { case 'd': case 'i': { const int number = va_arg(va, int); UnityPrintNumber((UNITY_INT)number); break; } #ifndef UNITY_EXCLUDE_FLOAT_PRINT case 'f': case 'g': { const double number = va_arg(va, double); UnityPrintFloat((UNITY_DOUBLE)number); break; } #endif case 'u': { const unsigned int number = va_arg(va, unsigned int); UnityPrintNumberUnsigned((UNITY_UINT)number); break; } case 'b': { const unsigned int number = va_arg(va, unsigned int); const UNITY_UINT mask = (UNITY_UINT)0 - (UNITY_UINT)1; UNITY_OUTPUT_CHAR('0'); UNITY_OUTPUT_CHAR('b'); UnityPrintMask(mask, (UNITY_UINT)number); break; } case 'x': case 'X': case 'p': { const unsigned int number = va_arg(va, unsigned int); UNITY_OUTPUT_CHAR('0'); UNITY_OUTPUT_CHAR('x'); UnityPrintNumberHex((UNITY_UINT)number, 8); break; } case 'c': { const int ch = va_arg(va, int); UnityPrintChar((const char *)&ch); break; } case 's': { const char * string = va_arg(va, const char *); UnityPrint(string); break; } case '%': { UnityPrintChar(pch); break; } default: { /* print the unknown format character */ UNITY_OUTPUT_CHAR('%'); UnityPrintChar(pch); break; } } } } #ifdef UNITY_OUTPUT_COLOR /* print ANSI escape code */ else if ((*pch == 27) && (*(pch + 1) == '[')) { pch += UnityPrintAnsiEscapeString(pch); continue; } #endif else if (*pch == '\n') { UNITY_PRINT_EOL(); } else { UnityPrintChar(pch); } pch++; } } } void UnityPrintF(const UNITY_LINE_TYPE line, const char* format, ...) { UnityTestResultsBegin(Unity.TestFile, line); UnityPrint("INFO"); if(format != NULL) { UnityPrint(": "); va_list va; va_start(va, format); UnityPrintFVA(format, va); va_end(va); } UNITY_PRINT_EOL(); } #endif /* ! UNITY_INCLUDE_PRINT_FORMATTED */ /*----------------------------------------------- * Control Functions *-----------------------------------------------*/ /*-----------------------------------------------*/ void UnityFail(const char* msg, const UNITY_LINE_TYPE line) { RETURN_IF_FAIL_OR_IGNORE; UnityTestResultsBegin(Unity.TestFile, line); UnityPrint(UnityStrFail); if (msg != NULL) { UNITY_OUTPUT_CHAR(':'); #ifdef UNITY_PRINT_TEST_CONTEXT UNITY_PRINT_TEST_CONTEXT(); #endif #ifndef UNITY_EXCLUDE_DETAILS if (Unity.CurrentDetail1) { UnityPrint(UnityStrDetail1Name); UnityPrint(Unity.CurrentDetail1); if (Unity.CurrentDetail2) { UnityPrint(UnityStrDetail2Name); UnityPrint(Unity.CurrentDetail2); } UnityPrint(UnityStrSpacer); } #endif if (msg[0] != ' ') { UNITY_OUTPUT_CHAR(' '); } UnityPrint(msg); } UNITY_FAIL_AND_BAIL; } /*-----------------------------------------------*/ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) { RETURN_IF_FAIL_OR_IGNORE; UnityTestResultsBegin(Unity.TestFile, line); UnityPrint(UnityStrIgnore); if (msg != NULL) { UNITY_OUTPUT_CHAR(':'); UNITY_OUTPUT_CHAR(' '); UnityPrint(msg); } UNITY_IGNORE_AND_BAIL; } /*-----------------------------------------------*/ void UnityMessage(const char* msg, const UNITY_LINE_TYPE line) { UnityTestResultsBegin(Unity.TestFile, line); UnityPrint("INFO"); if (msg != NULL) { UNITY_OUTPUT_CHAR(':'); UNITY_OUTPUT_CHAR(' '); UnityPrint(msg); } UNITY_PRINT_EOL(); } /*-----------------------------------------------*/ /* If we have not defined our own test runner, then include our default test runner to make life easier */ #ifndef UNITY_SKIP_DEFAULT_RUNNER void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) { Unity.CurrentTestName = FuncName; Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum; Unity.NumberOfTests++; UNITY_CLR_DETAILS(); UNITY_EXEC_TIME_START(); if (TEST_PROTECT()) { setUp(); Func(); } if (TEST_PROTECT()) { tearDown(); } UNITY_EXEC_TIME_STOP(); UnityConcludeTest(); } #endif /*-----------------------------------------------*/ void UnitySetTestFile(const char* filename) { Unity.TestFile = filename; } /*-----------------------------------------------*/ void UnityBegin(const char* filename) { Unity.TestFile = filename; Unity.CurrentTestName = NULL; Unity.CurrentTestLineNumber = 0; Unity.NumberOfTests = 0; Unity.TestFailures = 0; Unity.TestIgnores = 0; Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; UNITY_CLR_DETAILS(); UNITY_OUTPUT_START(); } /*-----------------------------------------------*/ int UnityEnd(void) { UNITY_PRINT_EOL(); UnityPrint(UnityStrBreaker); UNITY_PRINT_EOL(); UnityPrintNumber((UNITY_INT)(Unity.NumberOfTests)); UnityPrint(UnityStrResultsTests); UnityPrintNumber((UNITY_INT)(Unity.TestFailures)); UnityPrint(UnityStrResultsFailures); UnityPrintNumber((UNITY_INT)(Unity.TestIgnores)); UnityPrint(UnityStrResultsIgnored); UNITY_PRINT_EOL(); if (Unity.TestFailures == 0U) { UnityPrint(UnityStrOk); } else { UnityPrint(UnityStrFail); #ifdef UNITY_DIFFERENTIATE_FINAL_FAIL UNITY_OUTPUT_CHAR('E'); UNITY_OUTPUT_CHAR('D'); #endif } UNITY_PRINT_EOL(); UNITY_FLUSH_CALL(); UNITY_OUTPUT_COMPLETE(); return (int)(Unity.TestFailures); } /*----------------------------------------------- * Command Line Argument Support *-----------------------------------------------*/ #ifdef UNITY_USE_COMMAND_LINE_ARGS char* UnityOptionIncludeNamed = NULL; char* UnityOptionExcludeNamed = NULL; int UnityVerbosity = 1; /*-----------------------------------------------*/ int UnityParseOptions(int argc, char** argv) { int i; UnityOptionIncludeNamed = NULL; UnityOptionExcludeNamed = NULL; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'l': /* list tests */ return -1; case 'n': /* include tests with name including this string */ case 'f': /* an alias for -n */ if (argv[i][2] == '=') { UnityOptionIncludeNamed = &argv[i][3]; } else if (++i < argc) { UnityOptionIncludeNamed = argv[i]; } else { UnityPrint("ERROR: No Test String to Include Matches For"); UNITY_PRINT_EOL(); return 1; } break; case 'q': /* quiet */ UnityVerbosity = 0; break; case 'v': /* verbose */ UnityVerbosity = 2; break; case 'x': /* exclude tests with name including this string */ if (argv[i][2] == '=') { UnityOptionExcludeNamed = &argv[i][3]; } else if (++i < argc) { UnityOptionExcludeNamed = argv[i]; } else { UnityPrint("ERROR: No Test String to Exclude Matches For"); UNITY_PRINT_EOL(); return 1; } break; default: UnityPrint("ERROR: Unknown Option "); UNITY_OUTPUT_CHAR(argv[i][1]); UNITY_PRINT_EOL(); return 1; } } } return 0; } /*-----------------------------------------------*/ int IsStringInBiggerString(const char* longstring, const char* shortstring) { const char* lptr = longstring; const char* sptr = shortstring; const char* lnext = lptr; if (*sptr == '*') { return 1; } while (*lptr) { lnext = lptr + 1; /* If they current bytes match, go on to the next bytes */ while (*lptr && *sptr && (*lptr == *sptr)) { lptr++; sptr++; /* We're done if we match the entire string or up to a wildcard */ if (*sptr == '*') return 1; if (*sptr == ',') return 1; if (*sptr == '"') return 1; if (*sptr == '\'') return 1; if (*sptr == ':') return 2; if (*sptr == 0) return 1; } /* Otherwise we start in the long pointer 1 character further and try again */ lptr = lnext; sptr = shortstring; } return 0; } /*-----------------------------------------------*/ int UnityStringArgumentMatches(const char* str) { int retval; const char* ptr1; const char* ptr2; const char* ptrf; /* Go through the options and get the substrings for matching one at a time */ ptr1 = str; while (ptr1[0] != 0) { if ((ptr1[0] == '"') || (ptr1[0] == '\'')) { ptr1++; } /* look for the start of the next partial */ ptr2 = ptr1; ptrf = 0; do { ptr2++; if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')) { ptrf = &ptr2[1]; } } while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')); while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ','))) { ptr2++; } /* done if complete filename match */ retval = IsStringInBiggerString(Unity.TestFile, ptr1); if (retval == 1) { return retval; } /* done if testname match after filename partial match */ if ((retval == 2) && (ptrf != 0)) { if (IsStringInBiggerString(Unity.CurrentTestName, ptrf)) { return 1; } } /* done if complete testname match */ if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1) { return 1; } ptr1 = ptr2; } /* we couldn't find a match for any substrings */ return 0; } /*-----------------------------------------------*/ int UnityTestMatches(void) { /* Check if this test name matches the included test pattern */ int retval; if (UnityOptionIncludeNamed) { retval = UnityStringArgumentMatches(UnityOptionIncludeNamed); } else { retval = 1; } /* Check if this test name matches the excluded test pattern */ if (UnityOptionExcludeNamed) { if (UnityStringArgumentMatches(UnityOptionExcludeNamed)) { retval = 0; } } return retval; } #endif /* UNITY_USE_COMMAND_LINE_ARGS */ /*-----------------------------------------------*/ test/unity/unity.h000066400000000000000000002556671455045705600145660ustar00rootroot00000000000000/* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007-21 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_FRAMEWORK_H #define UNITY_FRAMEWORK_H #define UNITY #define UNITY_VERSION_MAJOR 2 #define UNITY_VERSION_MINOR 5 #define UNITY_VERSION_BUILD 2 #define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD) #ifdef __cplusplus extern "C" { #endif #include "unity_internals.h" /*------------------------------------------------------- * Test Setup / Teardown *-------------------------------------------------------*/ /* These functions are intended to be called before and after each test. * If using unity directly, these will need to be provided for each test * executable built. If you are using the test runner generator and/or * Ceedling, these are optional. */ void setUp(void); void tearDown(void); /* These functions are intended to be called at the beginning and end of an * entire test suite. suiteTearDown() is passed the number of tests that * failed, and its return value becomes the exit code of main(). If using * Unity directly, you're in charge of calling these if they are desired. * If using Ceedling or the test runner generator, these will be called * automatically if they exist. */ void suiteSetUp(void); int suiteTearDown(int num_failures); /*------------------------------------------------------- * Test Reset and Verify *-------------------------------------------------------*/ /* These functions are intended to be called before during tests in order * to support complex test loops, etc. Both are NOT built into Unity. Instead * the test runner generator will create them. resetTest will run teardown and * setup again, verifying any end-of-test needs between. verifyTest will only * run the verification. */ void resetTest(void); void verifyTest(void); /*------------------------------------------------------- * Configuration Options *------------------------------------------------------- * All options described below should be passed as a compiler flag to all files using Unity. If you must add #defines, place them BEFORE the #include above. * Integers/longs/pointers * - Unity attempts to automatically discover your integer sizes * - define UNITY_EXCLUDE_STDINT_H to stop attempting to look in * - define UNITY_EXCLUDE_LIMITS_H to stop attempting to look in * - If you cannot use the automatic methods above, you can force Unity by using these options: * - define UNITY_SUPPORT_64 * - set UNITY_INT_WIDTH * - set UNITY_LONG_WIDTH * - set UNITY_POINTER_WIDTH * Floats * - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons * - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT * - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats * - define UNITY_INCLUDE_DOUBLE to allow double floating point comparisons * - define UNITY_EXCLUDE_DOUBLE to disallow double floating point comparisons (default) * - define UNITY_DOUBLE_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_DOUBLE * - define UNITY_DOUBLE_TYPE to specify something other than double * - define UNITY_EXCLUDE_FLOAT_PRINT to trim binary size, won't print floating point values in errors * Output * - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired * - define UNITY_DIFFERENTIATE_FINAL_FAIL to print FAILED (vs. FAIL) at test end summary - for automated search for failure * Optimization * - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge * - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests. * Test Cases * - define UNITY_SUPPORT_TEST_CASES to include the TEST_CASE macro, though really it's mostly about the runner generator script * Parameterized Tests * - you'll want to create a define of TEST_CASE(...) which basically evaluates to nothing * Tests with Arguments * - you'll want to define UNITY_USE_COMMAND_LINE_ARGS if you have the test runner passing arguments to Unity *------------------------------------------------------- * Basic Fail and Ignore *-------------------------------------------------------*/ #define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, (message)) #define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL) #define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, (message)) #define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL) #define TEST_MESSAGE(message) UnityMessage((message), __LINE__) #define TEST_ONLY() #ifdef UNITY_INCLUDE_PRINT_FORMATTED #define TEST_PRINTF(message, ...) UnityPrintF(__LINE__, (message), __VA_ARGS__) #endif /* It is not necessary for you to call PASS. A PASS condition is assumed if nothing fails. * This method allows you to abort a test immediately with a PASS state, ignoring the remainder of the test. */ #define TEST_PASS() TEST_ABORT() #define TEST_PASS_MESSAGE(message) do { UnityMessage((message), __LINE__); TEST_ABORT(); } while(0) /* This macro does nothing, but it is useful for build tools (like Ceedling) to make use of this to figure out * which files should be linked to in order to perform a test. Use it like TEST_FILE("sandwiches.c") */ #define TEST_FILE(a) /*------------------------------------------------------- * Test Asserts (simple) *-------------------------------------------------------*/ /* Boolean */ #define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE") #define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE") #define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE") #define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE") #define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL") #define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL") #define TEST_ASSERT_EMPTY(pointer) UNITY_TEST_ASSERT_EMPTY( (pointer), __LINE__, " Expected Empty") #define TEST_ASSERT_NOT_EMPTY(pointer) UNITY_TEST_ASSERT_NOT_EMPTY((pointer), __LINE__, " Expected Non-Empty") /* Integers (of all sizes) */ #define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_size_t(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_CHAR(expected, actual) UNITY_TEST_ASSERT_EQUAL_CHAR((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (UNITY_UINT)(-1), (actual), __LINE__, NULL) #define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (UNITY_UINT)(0), (actual), __LINE__, NULL) #define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((UNITY_UINT)1 << (bit)), (UNITY_UINT)(-1), (actual), __LINE__, NULL) #define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((UNITY_UINT)1 << (bit)), (UNITY_UINT)(0), (actual), __LINE__, NULL) /* Integer Not Equal To (of all sizes) */ #define TEST_ASSERT_NOT_EQUAL_INT(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_INT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_INT8(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_INT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_INT16(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_INT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_INT32(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_INT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_INT64(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_INT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_UINT(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_UINT8(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_UINT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_UINT16(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_UINT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_UINT32(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_UINT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_UINT64(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_UINT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_size_t(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_HEX8(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_HEX8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_HEX16(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_HEX16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_HEX32(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_HEX32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_HEX64(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_HEX64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL_CHAR(threshold, actual) UNITY_TEST_ASSERT_NOT_EQUAL_CHAR((threshold), (actual), __LINE__, NULL) /* Integer Greater Than/ Less Than (of all sizes) */ #define TEST_ASSERT_GREATER_THAN(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_INT(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_INT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_INT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_INT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_INT64(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_UINT(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_UINT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_UINT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_UINT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_UINT64(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_size_t(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_HEX8(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_HEX16(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_HEX32(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_HEX64(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_THAN_CHAR(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_CHAR((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_INT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_INT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_INT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_INT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_INT64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_UINT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_UINT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_UINT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_UINT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_UINT64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_size_t(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_HEX8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_HEX16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_HEX32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_HEX64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_THAN_CHAR(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_CHAR((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_INT(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_INT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_INT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_INT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_INT64(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT64(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_size_t(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_HEX8(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_HEX16(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_HEX32(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_HEX64(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_GREATER_OR_EQUAL_CHAR(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_CHAR((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_INT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_INT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_INT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_INT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_INT64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_UINT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_UINT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_UINT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_UINT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_UINT64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_size_t(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_HEX8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX8((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_HEX16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX16((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_HEX32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX32((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_HEX64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64((threshold), (actual), __LINE__, NULL) #define TEST_ASSERT_LESS_OR_EQUAL_CHAR(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_CHAR((threshold), (actual), __LINE__, NULL) /* Integer Ranges (of all sizes) */ #define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_INT8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_INT16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT16_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_INT32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT32_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_INT64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT64_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_UINT8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT8_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_UINT16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT16_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_UINT32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT32_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_UINT64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT64_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_size_t_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_CHAR_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_CHAR_WITHIN((delta), (expected), (actual), __LINE__, NULL) /* Integer Array Ranges (of all sizes) */ #define TEST_ASSERT_INT_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_INT8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_INT16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_INT32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_UINT_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_UINT8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_UINT16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_UINT32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_size_t_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_HEX_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_HEX8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_HEX16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_HEX32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) #define TEST_ASSERT_CHAR_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_CHAR_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) /* Structs and Strings */ #define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_STRING_LEN((expected), (actual), (len), __LINE__, NULL) #define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY((expected), (actual), (len), __LINE__, NULL) /* Arrays */ #define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_size_t_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((expected), (actual), (len), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EQUAL_CHAR_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_CHAR_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) /* Arrays Compared To Single Value */ #define TEST_ASSERT_EACH_EQUAL_INT(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_INT8(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT8((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_INT16(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT16((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT32((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT64((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_UINT(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_UINT8(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT8((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_UINT16(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT16((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_UINT32(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT32((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT64((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_size_t(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_HEX(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_HEX8(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX8((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_HEX16(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX16((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_HEX32(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX64((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_PTR(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_PTR((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_STRING(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_STRING((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_MEMORY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY((expected), (actual), (len), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_CHAR(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_CHAR((expected), (actual), (num_elements), __LINE__, NULL) /* Floating Point (If Enabled) */ #define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_FLOAT(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_FLOAT((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF((actual), __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF((actual), __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN((actual), __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_DETERMINATE(actual) UNITY_TEST_ASSERT_FLOAT_IS_DETERMINATE((actual), __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NOT_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF((actual), __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF((actual), __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN((actual), __LINE__, NULL) #define TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE((actual), __LINE__, NULL) /* Double (If Enabled) */ #define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE(expected, actual) UNITY_TEST_ASSERT_EQUAL_DOUBLE((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE((expected), (actual), (num_elements), __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF((actual), __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF((actual), __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN((actual), __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_DETERMINATE(actual) UNITY_TEST_ASSERT_DOUBLE_IS_DETERMINATE((actual), __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NOT_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF((actual), __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF((actual), __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN((actual), __LINE__, NULL) #define TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE((actual), __LINE__, NULL) /* Shorthand */ #ifdef UNITY_SHORTHAND_AS_OLD #define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal") #endif #ifdef UNITY_SHORTHAND_AS_INT #define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) #endif #ifdef UNITY_SHORTHAND_AS_MEM #define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_MEMORY((&expected), (&actual), sizeof(expected), __LINE__, NULL) #define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) #endif #ifdef UNITY_SHORTHAND_AS_RAW #define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) == (actual)), __LINE__, " Expected Equal") #define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal") #endif #ifdef UNITY_SHORTHAND_AS_NONE #define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) #define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) #endif /*------------------------------------------------------- * Test Asserts (with additional messages) *-------------------------------------------------------*/ /* Boolean */ #define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, (message)) #define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, (message)) #define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, (message)) #define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, (message)) #define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, (message)) #define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, (message)) #define TEST_ASSERT_EMPTY_MESSAGE(pointer, message) UNITY_TEST_ASSERT_EMPTY( (pointer), __LINE__, (message)) #define TEST_ASSERT_NOT_EMPTY_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_EMPTY((pointer), __LINE__, (message)) /* Integers (of all sizes) */ #define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_size_t_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (UNITY_UINT32)(-1), (actual), __LINE__, (message)) #define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (UNITY_UINT32)(0), (actual), __LINE__, (message)) #define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(-1), (actual), __LINE__, (message)) #define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(0), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_CHAR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_CHAR((expected), (actual), __LINE__, (message)) /* Integer Not Equal To (of all sizes) */ #define TEST_ASSERT_NOT_EQUAL_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_INT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_INT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_INT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_INT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_INT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_INT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_UINT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_UINT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_UINT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_UINT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_size_t_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_HEX8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_HEX16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_HEX32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_HEX64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_CHAR_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_CHAR((threshold), (actual), __LINE__, (message)) /* Integer Greater Than/ Less Than (of all sizes) */ #define TEST_ASSERT_GREATER_THAN_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_INT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_size_t_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_THAN_CHAR_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_CHAR((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_INT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_size_t_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_THAN_CHAR_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_CHAR((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_INT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_size_t_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_GREATER_OR_EQUAL_CHAR_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_CHAR((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_INT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_size_t_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX16((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX32((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_CHAR_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_CHAR((threshold), (actual), __LINE__, (message)) /* Integer Ranges (of all sizes) */ #define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_INT8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_INT16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT16_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_INT32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT32_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_INT64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT64_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_UINT8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT8_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_UINT16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT16_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_UINT32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT32_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_UINT64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT64_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_size_t_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_CHAR_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_CHAR_WITHIN((delta), (expected), (actual), __LINE__, (message)) /* Integer Array Ranges (of all sizes) */ #define TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_INT32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_UINT32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_size_t_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_HEX_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) #define TEST_ASSERT_CHAR_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_CHAR_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) /* Structs and Strings */ #define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_STRING_LEN((expected), (actual), (len), __LINE__, (message)) #define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY((expected), (actual), (len), __LINE__, (message)) /* Arrays */ #define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_size_t_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_PTR_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((expected), (actual), (len), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EQUAL_CHAR_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_CHAR_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) /* Arrays Compared To Single Value*/ #define TEST_ASSERT_EACH_EQUAL_INT_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_INT8_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT8((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_INT16_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT16((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_INT32_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT32((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_INT64_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT64((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_UINT_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_UINT8_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT8((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_UINT16_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT16((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_UINT32_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT32((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_UINT64_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT64((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_size_t_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_HEX_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_HEX8_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX8((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_HEX16_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX16((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_HEX32_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_HEX64_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX64((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_PTR_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_PTR((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_STRING_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_STRING((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_MEMORY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY((expected), (actual), (len), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_CHAR_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_CHAR((expected), (actual), (num_elements), __LINE__, (message)) /* Floating Point (If Enabled) */ #define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_FLOAT_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_FLOAT((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF((actual), __LINE__, (message)) #define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF((actual), __LINE__, (message)) #define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN((actual), __LINE__, (message)) #define TEST_ASSERT_FLOAT_IS_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_DETERMINATE((actual), __LINE__, (message)) #define TEST_ASSERT_FLOAT_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF((actual), __LINE__, (message)) #define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF((actual), __LINE__, (message)) #define TEST_ASSERT_FLOAT_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN((actual), __LINE__, (message)) #define TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE((actual), __LINE__, (message)) /* Double (If Enabled) */ #define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_DOUBLE_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_EACH_EQUAL_DOUBLE_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE((expected), (actual), (num_elements), __LINE__, (message)) #define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF((actual), __LINE__, (message)) #define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF((actual), __LINE__, (message)) #define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN((actual), __LINE__, (message)) #define TEST_ASSERT_DOUBLE_IS_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_DETERMINATE((actual), __LINE__, (message)) #define TEST_ASSERT_DOUBLE_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF((actual), __LINE__, (message)) #define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF((actual), __LINE__, (message)) #define TEST_ASSERT_DOUBLE_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN((actual), __LINE__, (message)) #define TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE((actual), __LINE__, (message)) /* Shorthand */ #ifdef UNITY_SHORTHAND_AS_OLD #define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, (message)) #define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, (message)) #endif #ifdef UNITY_SHORTHAND_AS_INT #define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message) #define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) #endif #ifdef UNITY_SHORTHAND_AS_MEM #define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_MEMORY((&expected), (&actual), sizeof(expected), __LINE__, message) #define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) #endif #ifdef UNITY_SHORTHAND_AS_RAW #define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) == (actual)), __LINE__, message) #define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message) #endif #ifdef UNITY_SHORTHAND_AS_NONE #define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) #define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) #endif /* end of UNITY_FRAMEWORK_H */ #ifdef __cplusplus } #endif #endif test/unity/unity_fixture.c000066400000000000000000000177071455045705600163160ustar00rootroot00000000000000//- Copyright (c) 2010 James Grenning and Contributed to Unity Project /* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #include #include "unity_fixture.h" #include "unity_internals.h" UNITY_FIXTURE_T UnityFixture; //If you decide to use the function pointer approach. int (*outputChar)(int) = putchar; int verbose = 0; void setUp(void) { /*does nothing*/ } void tearDown(void) { /*does nothing*/ } void announceTestRun(unsigned int runNumber) { UnityPrint("Unity test run "); UnityPrintNumber(runNumber+1); UnityPrint(" of "); UnityPrintNumber(UnityFixture.RepeatCount); UNITY_OUTPUT_CHAR('\n'); } int UnityMain(int argc, char* argv[], void (*runAllTests)()) { int result = UnityGetCommandLineOptions(argc, argv); unsigned int r; if (result != 0) return result; for (r = 0; r < UnityFixture.RepeatCount; r++) { announceTestRun(r); UnityBegin(""); runAllTests(); UNITY_OUTPUT_CHAR('\n'); UnityEnd(); } return UnityFailureCount(); } static int selected(const char * filter, const char * name) { if (filter == 0) return 1; return strstr(name, filter) ? 1 : 0; } static int testSelected(const char* test) { return selected(UnityFixture.NameFilter, test); } static int groupSelected(const char* group) { return selected(UnityFixture.GroupFilter, group); } static void runTestCase() { } void UnityTestRunner(unityfunction* setup, unityfunction* testBody, unityfunction* teardown, const char * printableName, const char * group, const char * name, const char * file, int line) { if (testSelected(name) && groupSelected(group)) { Unity.CurrentTestFailed = 0; Unity.TestFile = file; Unity.CurrentTestName = printableName; Unity.CurrentTestLineNumber = line; if (!UnityFixture.Verbose) UNITY_OUTPUT_CHAR('.'); else UnityPrint(printableName); Unity.NumberOfTests++; UnityMalloc_StartTest(); UnityPointer_Init(); runTestCase(); if (TEST_PROTECT()) { setup(); testBody(); } if (TEST_PROTECT()) { teardown(); } if (TEST_PROTECT()) { UnityPointer_UndoAllSets(); if (!Unity.CurrentTestFailed) UnityMalloc_EndTest(); } UnityConcludeFixtureTest(); } } void UnityIgnoreTest(const char * printableName) { Unity.NumberOfTests++; Unity.CurrentTestIgnored = 1; if (!UnityFixture.Verbose) UNITY_OUTPUT_CHAR('!'); else UnityPrint(printableName); UnityConcludeFixtureTest(); } //------------------------------------------------- //Malloc and free stuff // #define MALLOC_DONT_FAIL -1 static int malloc_count; static int malloc_fail_countdown = MALLOC_DONT_FAIL; void UnityMalloc_StartTest() { malloc_count = 0; malloc_fail_countdown = MALLOC_DONT_FAIL; } void UnityMalloc_EndTest() { malloc_fail_countdown = MALLOC_DONT_FAIL; if (malloc_count != 0) { TEST_FAIL_MESSAGE("This test leaks!"); } } void UnityMalloc_MakeMallocFailAfterCount(int countdown) { malloc_fail_countdown = countdown; } #ifdef malloc #undef malloc #endif #ifdef free #undef free #endif #include #include typedef struct GuardBytes { size_t size; char guard[sizeof(size_t)]; } Guard; static const char * end = "END"; void * unity_malloc(size_t size) { char* mem; Guard* guard; if (malloc_fail_countdown != MALLOC_DONT_FAIL) { if (malloc_fail_countdown == 0) return NULL; malloc_fail_countdown--; } malloc_count++; guard = (Guard*)malloc(size + sizeof(Guard) + 4); guard->size = size; mem = (char*)&(guard[1]); memcpy(&mem[size], end, strlen(end) + 1); return (void*)mem; } static int isOverrun(void * mem) { Guard* guard = (Guard*)mem; char* memAsChar = (char*)mem; guard--; return strcmp(&memAsChar[guard->size], end) != 0; } static void release_memory(void * mem) { Guard* guard = (Guard*)mem; guard--; malloc_count--; free(guard); } void unity_free(void * mem) { int overrun = isOverrun(mem);//strcmp(&memAsChar[guard->size], end) != 0; release_memory(mem); if (overrun) { TEST_FAIL_MESSAGE("Buffer overrun detected during free()"); } } void* unity_calloc(size_t num, size_t size) { void* mem = unity_malloc(num * size); memset(mem, 0, num*size); return mem; } void* unity_realloc(void * oldMem, size_t size) { Guard* guard = (Guard*)oldMem; // char* memAsChar = (char*)oldMem; void* newMem; if (oldMem == 0) return unity_malloc(size); guard--; if (isOverrun(oldMem)) { release_memory(oldMem); TEST_FAIL_MESSAGE("Buffer overrun detected during realloc()"); } if (size == 0) { release_memory(oldMem); return NULL; } if (guard->size >= size) return oldMem; newMem = unity_malloc(size); memcpy(newMem, oldMem, guard->size); unity_free(oldMem); return newMem; } //-------------------------------------------------------- //Automatic pointer restoration functions typedef struct _PointerPair { struct _PointerPair * next; void ** pointer; void * old_value; } PointerPair; enum {MAX_POINTERS=50}; static PointerPair pointer_store[MAX_POINTERS]; static int pointer_index = 0; void UnityPointer_Init() { pointer_index = 0; } void UnityPointer_Set(void ** pointer, void * newValue) { if (pointer_index >= MAX_POINTERS) TEST_FAIL_MESSAGE("Too many pointers set"); pointer_store[pointer_index].pointer = pointer; pointer_store[pointer_index].old_value = *pointer; *pointer = newValue; pointer_index++; } void UnityPointer_UndoAllSets() { while (pointer_index > 0) { pointer_index--; *(pointer_store[pointer_index].pointer) = pointer_store[pointer_index].old_value; } } int UnityFailureCount() { return Unity.TestFailures; } int UnityGetCommandLineOptions(int argc, char* argv[]) { int i; UnityFixture.Verbose = 0; UnityFixture.GroupFilter = 0; UnityFixture.NameFilter = 0; UnityFixture.RepeatCount = 1; if (argc == 1) return 0; for (i = 1; i < argc; ) { if (strcmp(argv[i], "-v") == 0) { UnityFixture.Verbose = 1; i++; } else if (strcmp(argv[i], "-g") == 0) { i++; if (i >= argc) return 1; UnityFixture.GroupFilter = argv[i]; i++; } else if (strcmp(argv[i], "-n") == 0) { i++; if (i >= argc) return 1; UnityFixture.NameFilter = argv[i]; i++; } else if (strcmp(argv[i], "-r") == 0) { UnityFixture.RepeatCount = 2; i++; if (i < argc) { if (*(argv[i]) >= '0' && *(argv[i]) <= '9') { UnityFixture.RepeatCount = atoi(argv[i]); i++; } } } } return 0; } void UnityConcludeFixtureTest() { if (Unity.CurrentTestIgnored) { if (UnityFixture.Verbose) { UNITY_OUTPUT_CHAR('\n'); } Unity.TestIgnores++; } else if (!Unity.CurrentTestFailed) { if (UnityFixture.Verbose) { UnityPrint(" PASS"); UNITY_OUTPUT_CHAR('\n'); } } else if (Unity.CurrentTestFailed) { Unity.TestFailures++; } Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; } test/unity/unity_fixture.h000066400000000000000000000055671455045705600163240ustar00rootroot00000000000000//- Copyright (c) 2010 James Grenning and Contributed to Unity Project /* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_FIXTURE_H_ #define UNITY_FIXTURE_H_ #include "unity.h" #include "unity_internals.h" #include "unity_fixture_malloc_overrides.h" #include "unity_fixture_internals.h" int UnityMain(int argc, char* argv[], void (*runAllTests)()); #define TEST_GROUP(group)\ int TEST_GROUP_##group = 0 #define TEST_SETUP(group) void TEST_##group##_SETUP() #define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN() #define TEST(group, name) \ void TEST_##group##_##name##_();\ void TEST_##group##_##name##_run()\ {\ UnityTestRunner(TEST_##group##_SETUP,\ TEST_##group##_##name##_,\ TEST_##group##_TEAR_DOWN,\ "TEST(" #group ", " #name ")",\ #group, #name,\ __FILE__, __LINE__);\ }\ void TEST_##group##_##name##_() #define IGNORE_TEST(group, name) \ void TEST_##group##_##name##_();\ void TEST_##group##_##name##_run()\ {\ UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")");\ }\ void TEST_##group##_##name##_() #define DECLARE_TEST_CASE(group, name) \ void TEST_##group##_##name##_run() #define RUN_TEST_CASE(group, name) \ { DECLARE_TEST_CASE(group, name);\ TEST_##group##_##name##_run(); } //This goes at the bottom of each test file or in a separate c file #define TEST_GROUP_RUNNER(group)\ void TEST_##group##_GROUP_RUNNER_runAll();\ void TEST_##group##_GROUP_RUNNER()\ {\ TEST_##group##_GROUP_RUNNER_runAll();\ }\ void TEST_##group##_GROUP_RUNNER_runAll() //Call this from main #define RUN_TEST_GROUP(group)\ { void TEST_##group##_GROUP_RUNNER();\ TEST_##group##_GROUP_RUNNER(); } //CppUTest Compatibility Macros #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&ptr, (void*)newPointerValue) #define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR(expected, actual) #define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual)) #define FAIL(message) TEST_FAIL((message)) #define CHECK(condition) TEST_ASSERT_TRUE((condition)) #define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual)) #define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual)) #define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_FLOAT_WITHIN(((expected), (actual), (delta)) void UnityMalloc_MakeMallocFailAfterCount(int count); #endif /* UNITY_FIXTURE_H_ */ test/unity/unity_fixture_internals.h000066400000000000000000000026321455045705600203710ustar00rootroot00000000000000//- Copyright (c) 2010 James Grenning and Contributed to Unity Project /* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_FIXTURE_INTERNALS_H_ #define UNITY_FIXTURE_INTERNALS_H_ typedef struct _UNITY_FIXTURE_T { int Verbose; unsigned int RepeatCount; const char* NameFilter; const char* GroupFilter; } UNITY_FIXTURE_T; typedef void unityfunction(); void UnityTestRunner(unityfunction * setup, unityfunction * body, unityfunction * teardown, const char * printableName, const char * group, const char * name, const char * file, int line); void UnityIgnoreTest(const char * printableName); void UnityMalloc_StartTest(); void UnityMalloc_EndTest(); int UnityFailureCount(); int UnityGetCommandLineOptions(int argc, char* argv[]); void UnityConcludeFixtureTest(); void UnityPointer_Set(void ** ptr, void * newValue); void UnityPointer_UndoAllSets(); void UnityPointer_Init(); void UnityAssertEqualPointer(const void * expected, const void * actual, const char* msg, const UNITY_LINE_TYPE lineNumber); #endif /* UNITY_FIXTURE_INTERNALS_H_ */ test/unity/unity_fixture_malloc_overrides.h000066400000000000000000000011271455045705600217210ustar00rootroot00000000000000//- Copyright (c) 2010 James Grenning and Contributed to Unity Project /* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_ #define UNITY_FIXTURE_MALLOC_OVERRIDES_H_ #define malloc unity_malloc #define calloc unity_calloc #define realloc unity_realloc #define free unity_free #endif /* UNITY_FIXTURE_MALLOC_OVERRIDES_H_ */ test/unity/unity_internals.h000066400000000000000000002516221455045705600166300ustar00rootroot00000000000000/* ========================================== Unity Project - A Test Framework for C Copyright (c) 2007-21 Mike Karlesky, Mark VanderVoord, Greg Williams [Released under MIT License. Please refer to license.txt for details] ========================================== */ #ifndef UNITY_INTERNALS_H #define UNITY_INTERNALS_H #ifdef UNITY_INCLUDE_CONFIG_H #include "unity_config.h" #endif #ifndef UNITY_EXCLUDE_SETJMP_H #include #endif #ifndef UNITY_EXCLUDE_MATH_H #include #endif #ifndef UNITY_EXCLUDE_STDDEF_H #include #endif #ifdef UNITY_INCLUDE_PRINT_FORMATTED #include #endif /* Unity Attempts to Auto-Detect Integer Types * Attempt 1: UINT_MAX, ULONG_MAX in , or default to 32 bits * Attempt 2: UINTPTR_MAX in , or default to same size as long * The user may override any of these derived constants: * UNITY_INT_WIDTH, UNITY_LONG_WIDTH, UNITY_POINTER_WIDTH */ #ifndef UNITY_EXCLUDE_STDINT_H #include #endif #ifndef UNITY_EXCLUDE_LIMITS_H #include #endif #if defined __GNUC__ # define UNITY_FUNCTION_ATTR(a) __attribute__((a)) #else # define UNITY_FUNCTION_ATTR(a) /* ignore */ #endif /*------------------------------------------------------- * Guess Widths If Not Specified *-------------------------------------------------------*/ /* Determine the size of an int, if not already specified. * We cannot use sizeof(int), because it is not yet defined * at this stage in the translation of the C program. * Also sizeof(int) does return the size in addressable units on all platforms, * which may not necessarily be the size in bytes. * Therefore, infer it from UINT_MAX if possible. */ #ifndef UNITY_INT_WIDTH #ifdef UINT_MAX #if (UINT_MAX == 0xFFFF) #define UNITY_INT_WIDTH (16) #elif (UINT_MAX == 0xFFFFFFFF) #define UNITY_INT_WIDTH (32) #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF) #define UNITY_INT_WIDTH (64) #endif #else /* Set to default */ #define UNITY_INT_WIDTH (32) #endif /* UINT_MAX */ #endif /* Determine the size of a long, if not already specified. */ #ifndef UNITY_LONG_WIDTH #ifdef ULONG_MAX #if (ULONG_MAX == 0xFFFF) #define UNITY_LONG_WIDTH (16) #elif (ULONG_MAX == 0xFFFFFFFF) #define UNITY_LONG_WIDTH (32) #elif (ULONG_MAX == 0xFFFFFFFFFFFFFFFF) #define UNITY_LONG_WIDTH (64) #endif #else /* Set to default */ #define UNITY_LONG_WIDTH (32) #endif /* ULONG_MAX */ #endif /* Determine the size of a pointer, if not already specified. */ #ifndef UNITY_POINTER_WIDTH #ifdef UINTPTR_MAX #if (UINTPTR_MAX <= 0xFFFF) #define UNITY_POINTER_WIDTH (16) #elif (UINTPTR_MAX <= 0xFFFFFFFF) #define UNITY_POINTER_WIDTH (32) #elif (UINTPTR_MAX <= 0xFFFFFFFFFFFFFFFF) #define UNITY_POINTER_WIDTH (64) #endif #else /* Set to default */ #define UNITY_POINTER_WIDTH UNITY_LONG_WIDTH #endif /* UINTPTR_MAX */ #endif /*------------------------------------------------------- * Int Support (Define types based on detected sizes) *-------------------------------------------------------*/ #if (UNITY_INT_WIDTH == 32) typedef unsigned char UNITY_UINT8; typedef unsigned short UNITY_UINT16; typedef unsigned int UNITY_UINT32; typedef signed char UNITY_INT8; typedef signed short UNITY_INT16; typedef signed int UNITY_INT32; #elif (UNITY_INT_WIDTH == 16) typedef unsigned char UNITY_UINT8; typedef unsigned int UNITY_UINT16; typedef unsigned long UNITY_UINT32; typedef signed char UNITY_INT8; typedef signed int UNITY_INT16; typedef signed long UNITY_INT32; #else #error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported) #endif /*------------------------------------------------------- * 64-bit Support *-------------------------------------------------------*/ /* Auto-detect 64 Bit Support */ #ifndef UNITY_SUPPORT_64 #if UNITY_LONG_WIDTH == 64 || UNITY_POINTER_WIDTH == 64 #define UNITY_SUPPORT_64 #endif #endif /* 64-Bit Support Dependent Configuration */ #ifndef UNITY_SUPPORT_64 /* No 64-bit Support */ typedef UNITY_UINT32 UNITY_UINT; typedef UNITY_INT32 UNITY_INT; #define UNITY_MAX_NIBBLES (8) /* Maximum number of nibbles in a UNITY_(U)INT */ #else /* 64-bit Support */ #if (UNITY_LONG_WIDTH == 32) typedef unsigned long long UNITY_UINT64; typedef signed long long UNITY_INT64; #elif (UNITY_LONG_WIDTH == 64) typedef unsigned long UNITY_UINT64; typedef signed long UNITY_INT64; #else #error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported) #endif typedef UNITY_UINT64 UNITY_UINT; typedef UNITY_INT64 UNITY_INT; #define UNITY_MAX_NIBBLES (16) /* Maximum number of nibbles in a UNITY_(U)INT */ #endif /*------------------------------------------------------- * Pointer Support *-------------------------------------------------------*/ #if (UNITY_POINTER_WIDTH == 32) #define UNITY_PTR_TO_INT UNITY_INT32 #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32 #elif (UNITY_POINTER_WIDTH == 64) #define UNITY_PTR_TO_INT UNITY_INT64 #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64 #elif (UNITY_POINTER_WIDTH == 16) #define UNITY_PTR_TO_INT UNITY_INT16 #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16 #else #error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported) #endif #ifndef UNITY_PTR_ATTRIBUTE #define UNITY_PTR_ATTRIBUTE #endif #ifndef UNITY_INTERNAL_PTR #define UNITY_INTERNAL_PTR UNITY_PTR_ATTRIBUTE const void* #endif /*------------------------------------------------------- * Float Support *-------------------------------------------------------*/ #ifdef UNITY_EXCLUDE_FLOAT /* No Floating Point Support */ #ifndef UNITY_EXCLUDE_DOUBLE #define UNITY_EXCLUDE_DOUBLE /* Remove double when excluding float support */ #endif #ifndef UNITY_EXCLUDE_FLOAT_PRINT #define UNITY_EXCLUDE_FLOAT_PRINT #endif #else /* Floating Point Support */ #ifndef UNITY_FLOAT_PRECISION #define UNITY_FLOAT_PRECISION (0.00001f) #endif #ifndef UNITY_FLOAT_TYPE #define UNITY_FLOAT_TYPE float #endif typedef UNITY_FLOAT_TYPE UNITY_FLOAT; /* isinf & isnan macros should be provided by math.h */ #ifndef isinf /* The value of Inf - Inf is NaN */ #define isinf(n) (isnan((n) - (n)) && !isnan(n)) #endif #ifndef isnan /* NaN is the only floating point value that does NOT equal itself. * Therefore if n != n, then it is NaN. */ #define isnan(n) ((n != n) ? 1 : 0) #endif #endif /*------------------------------------------------------- * Double Float Support *-------------------------------------------------------*/ /* unlike float, we DON'T include by default */ #if defined(UNITY_EXCLUDE_DOUBLE) || !defined(UNITY_INCLUDE_DOUBLE) /* No Floating Point Support */ #ifndef UNITY_EXCLUDE_DOUBLE #define UNITY_EXCLUDE_DOUBLE #else #undef UNITY_INCLUDE_DOUBLE #endif #ifndef UNITY_EXCLUDE_FLOAT #ifndef UNITY_DOUBLE_TYPE #define UNITY_DOUBLE_TYPE double #endif typedef UNITY_FLOAT UNITY_DOUBLE; /* For parameter in UnityPrintFloat(UNITY_DOUBLE), which aliases to double or float */ #endif #else /* Double Floating Point Support */ #ifndef UNITY_DOUBLE_PRECISION #define UNITY_DOUBLE_PRECISION (1e-12) #endif #ifndef UNITY_DOUBLE_TYPE #define UNITY_DOUBLE_TYPE double #endif typedef UNITY_DOUBLE_TYPE UNITY_DOUBLE; #endif /*------------------------------------------------------- * Output Method: stdout (DEFAULT) *-------------------------------------------------------*/ #ifndef UNITY_OUTPUT_CHAR /* Default to using putchar, which is defined in stdio.h */ #include #define UNITY_OUTPUT_CHAR(a) (void)putchar(a) #else /* If defined as something else, make sure we declare it here so it's ready for use */ #ifdef UNITY_OUTPUT_CHAR_HEADER_DECLARATION extern void UNITY_OUTPUT_CHAR_HEADER_DECLARATION; #endif #endif #ifndef UNITY_OUTPUT_FLUSH #ifdef UNITY_USE_FLUSH_STDOUT /* We want to use the stdout flush utility */ #include #define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) #else /* We've specified nothing, therefore flush should just be ignored */ #define UNITY_OUTPUT_FLUSH() #endif #else /* If defined as something else, make sure we declare it here so it's ready for use */ #ifdef UNITY_OUTPUT_FLUSH_HEADER_DECLARATION extern void UNITY_OUTPUT_FLUSH_HEADER_DECLARATION; #endif #endif #ifndef UNITY_OUTPUT_FLUSH #define UNITY_FLUSH_CALL() #else #define UNITY_FLUSH_CALL() UNITY_OUTPUT_FLUSH() #endif #ifndef UNITY_PRINT_EOL #define UNITY_PRINT_EOL() UNITY_OUTPUT_CHAR('\n') #endif #ifndef UNITY_OUTPUT_START #define UNITY_OUTPUT_START() #endif #ifndef UNITY_OUTPUT_COMPLETE #define UNITY_OUTPUT_COMPLETE() #endif #ifdef UNITY_INCLUDE_EXEC_TIME #if !defined(UNITY_EXEC_TIME_START) && \ !defined(UNITY_EXEC_TIME_STOP) && \ !defined(UNITY_PRINT_EXEC_TIME) && \ !defined(UNITY_TIME_TYPE) /* If none any of these macros are defined then try to provide a default implementation */ #if defined(UNITY_CLOCK_MS) /* This is a simple way to get a default implementation on platforms that support getting a millisecond counter */ #define UNITY_TIME_TYPE UNITY_UINT #define UNITY_EXEC_TIME_START() Unity.CurrentTestStartTime = UNITY_CLOCK_MS() #define UNITY_EXEC_TIME_STOP() Unity.CurrentTestStopTime = UNITY_CLOCK_MS() #define UNITY_PRINT_EXEC_TIME() { \ UNITY_UINT execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); \ UnityPrint(" ("); \ UnityPrintNumberUnsigned(execTimeMs); \ UnityPrint(" ms)"); \ } #elif defined(_WIN32) #include #define UNITY_TIME_TYPE clock_t #define UNITY_GET_TIME(t) t = (clock_t)((clock() * 1000) / CLOCKS_PER_SEC) #define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) #define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) #define UNITY_PRINT_EXEC_TIME() { \ UNITY_UINT execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); \ UnityPrint(" ("); \ UnityPrintNumberUnsigned(execTimeMs); \ UnityPrint(" ms)"); \ } #elif defined(__unix__) #include #define UNITY_TIME_TYPE struct timespec #define UNITY_GET_TIME(t) clock_gettime(CLOCK_MONOTONIC, &t) #define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) #define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) #define UNITY_PRINT_EXEC_TIME() { \ UNITY_UINT execTimeMs = ((Unity.CurrentTestStopTime.tv_sec - Unity.CurrentTestStartTime.tv_sec) * 1000L); \ execTimeMs += ((Unity.CurrentTestStopTime.tv_nsec - Unity.CurrentTestStartTime.tv_nsec) / 1000000L); \ UnityPrint(" ("); \ UnityPrintNumberUnsigned(execTimeMs); \ UnityPrint(" ms)"); \ } #endif #endif #endif #ifndef UNITY_EXEC_TIME_START #define UNITY_EXEC_TIME_START() do{}while(0) #endif #ifndef UNITY_EXEC_TIME_STOP #define UNITY_EXEC_TIME_STOP() do{}while(0) #endif #ifndef UNITY_TIME_TYPE #define UNITY_TIME_TYPE UNITY_UINT #endif #ifndef UNITY_PRINT_EXEC_TIME #define UNITY_PRINT_EXEC_TIME() do{}while(0) #endif /*------------------------------------------------------- * Footprint *-------------------------------------------------------*/ #ifndef UNITY_LINE_TYPE #define UNITY_LINE_TYPE UNITY_UINT #endif #ifndef UNITY_COUNTER_TYPE #define UNITY_COUNTER_TYPE UNITY_UINT #endif /*------------------------------------------------------- * Internal Structs Needed *-------------------------------------------------------*/ typedef void (*UnityTestFunction)(void); #define UNITY_DISPLAY_RANGE_INT (0x10) #define UNITY_DISPLAY_RANGE_UINT (0x20) #define UNITY_DISPLAY_RANGE_HEX (0x40) #define UNITY_DISPLAY_RANGE_CHAR (0x80) typedef enum { UNITY_DISPLAY_STYLE_INT = (UNITY_INT_WIDTH / 8) + UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT, #ifdef UNITY_SUPPORT_64 UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT, #endif UNITY_DISPLAY_STYLE_UINT = (UNITY_INT_WIDTH / 8) + UNITY_DISPLAY_RANGE_UINT, UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT, UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT, UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT, #ifdef UNITY_SUPPORT_64 UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT, #endif UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX, UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX, UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX, #ifdef UNITY_SUPPORT_64 UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX, #endif UNITY_DISPLAY_STYLE_CHAR = 1 + UNITY_DISPLAY_RANGE_CHAR + UNITY_DISPLAY_RANGE_INT, UNITY_DISPLAY_STYLE_UNKNOWN } UNITY_DISPLAY_STYLE_T; typedef enum { UNITY_WITHIN = 0x0, UNITY_EQUAL_TO = 0x1, UNITY_GREATER_THAN = 0x2, UNITY_GREATER_OR_EQUAL = 0x2 + UNITY_EQUAL_TO, UNITY_SMALLER_THAN = 0x4, UNITY_SMALLER_OR_EQUAL = 0x4 + UNITY_EQUAL_TO, UNITY_NOT_EQUAL = 0x0, UNITY_UNKNOWN } UNITY_COMPARISON_T; #ifndef UNITY_EXCLUDE_FLOAT typedef enum UNITY_FLOAT_TRAIT { UNITY_FLOAT_IS_NOT_INF = 0, UNITY_FLOAT_IS_INF, UNITY_FLOAT_IS_NOT_NEG_INF, UNITY_FLOAT_IS_NEG_INF, UNITY_FLOAT_IS_NOT_NAN, UNITY_FLOAT_IS_NAN, UNITY_FLOAT_IS_NOT_DET, UNITY_FLOAT_IS_DET, UNITY_FLOAT_INVALID_TRAIT } UNITY_FLOAT_TRAIT_T; #endif typedef enum { UNITY_ARRAY_TO_VAL = 0, UNITY_ARRAY_TO_ARRAY, UNITY_ARRAY_UNKNOWN } UNITY_FLAGS_T; struct UNITY_STORAGE_T { const char* TestFile; const char* CurrentTestName; #ifndef UNITY_EXCLUDE_DETAILS const char* CurrentDetail1; const char* CurrentDetail2; #endif UNITY_LINE_TYPE CurrentTestLineNumber; UNITY_COUNTER_TYPE NumberOfTests; UNITY_COUNTER_TYPE TestFailures; UNITY_COUNTER_TYPE TestIgnores; UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; #ifdef UNITY_INCLUDE_EXEC_TIME UNITY_TIME_TYPE CurrentTestStartTime; UNITY_TIME_TYPE CurrentTestStopTime; #endif #ifndef UNITY_EXCLUDE_SETJMP_H jmp_buf AbortFrame; #endif }; extern struct UNITY_STORAGE_T Unity; /*------------------------------------------------------- * Test Suite Management *-------------------------------------------------------*/ void UnityBegin(const char* filename); int UnityEnd(void); void UnitySetTestFile(const char* filename); void UnityConcludeTest(void); #ifndef RUN_TEST void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum); #else #define UNITY_SKIP_DEFAULT_RUNNER #endif /*------------------------------------------------------- * Details Support *-------------------------------------------------------*/ #ifdef UNITY_EXCLUDE_DETAILS #define UNITY_CLR_DETAILS() #define UNITY_SET_DETAIL(d1) #define UNITY_SET_DETAILS(d1,d2) #else #define UNITY_CLR_DETAILS() { Unity.CurrentDetail1 = 0; Unity.CurrentDetail2 = 0; } #define UNITY_SET_DETAIL(d1) { Unity.CurrentDetail1 = (d1); Unity.CurrentDetail2 = 0; } #define UNITY_SET_DETAILS(d1,d2) { Unity.CurrentDetail1 = (d1); Unity.CurrentDetail2 = (d2); } #ifndef UNITY_DETAIL1_NAME #define UNITY_DETAIL1_NAME "Function" #endif #ifndef UNITY_DETAIL2_NAME #define UNITY_DETAIL2_NAME "Argument" #endif #endif #ifdef UNITY_PRINT_TEST_CONTEXT void UNITY_PRINT_TEST_CONTEXT(void); #endif /*------------------------------------------------------- * Test Output *-------------------------------------------------------*/ void UnityPrint(const char* string); #ifdef UNITY_INCLUDE_PRINT_FORMATTED void UnityPrintF(const UNITY_LINE_TYPE line, const char* format, ...); #endif void UnityPrintLen(const char* string, const UNITY_UINT32 length); void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number); void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style); void UnityPrintNumber(const UNITY_INT number_to_print); void UnityPrintNumberUnsigned(const UNITY_UINT number); void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print); #ifndef UNITY_EXCLUDE_FLOAT_PRINT void UnityPrintFloat(const UNITY_DOUBLE input_number); #endif /*------------------------------------------------------- * Test Assertion Functions *------------------------------------------------------- * Use the macros below this section instead of calling * these directly. The macros have a consistent naming * convention and will pull in file and line information * for you. */ void UnityAssertEqualNumber(const UNITY_INT expected, const UNITY_INT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold, const UNITY_INT actual, const UNITY_COMPARISON_T compare, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style, const UNITY_FLAGS_T flags); void UnityAssertBits(const UNITY_INT mask, const UNITY_INT expected, const UNITY_INT actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualString(const char* expected, const char* actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualStringLen(const char* expected, const char* actual, const UNITY_UINT32 length, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualStringArray( UNITY_INTERNAL_PTR expected, const char** actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags); void UnityAssertEqualMemory( UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 length, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags); void UnityAssertNumbersWithin(const UNITY_UINT delta, const UNITY_INT expected, const UNITY_INT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); void UnityAssertNumbersArrayWithin(const UNITY_UINT delta, UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style, const UNITY_FLAGS_T flags); #ifndef UNITY_EXCLUDE_SETJMP_H void UnityFail(const char* message, const UNITY_LINE_TYPE line) UNITY_FUNCTION_ATTR(noreturn); void UnityIgnore(const char* message, const UNITY_LINE_TYPE line) UNITY_FUNCTION_ATTR(noreturn); #else void UnityFail(const char* message, const UNITY_LINE_TYPE line); void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); #endif void UnityMessage(const char* message, const UNITY_LINE_TYPE line); #ifndef UNITY_EXCLUDE_FLOAT void UnityAssertFloatsWithin(const UNITY_FLOAT delta, const UNITY_FLOAT expected, const UNITY_FLOAT actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected, UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags); void UnityAssertFloatSpecial(const UNITY_FLOAT actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLOAT_TRAIT_T style); #endif #ifndef UNITY_EXCLUDE_DOUBLE void UnityAssertDoublesWithin(const UNITY_DOUBLE delta, const UNITY_DOUBLE expected, const UNITY_DOUBLE actual, const char* msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected, UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual, const UNITY_UINT32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags); void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual, const char* msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLOAT_TRAIT_T style); #endif /*------------------------------------------------------- * Helpers *-------------------------------------------------------*/ UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size); #ifndef UNITY_EXCLUDE_FLOAT UNITY_INTERNAL_PTR UnityFloatToPtr(const float num); #endif #ifndef UNITY_EXCLUDE_DOUBLE UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num); #endif /*------------------------------------------------------- * Error Strings We Might Need *-------------------------------------------------------*/ extern const char UnityStrOk[]; extern const char UnityStrPass[]; extern const char UnityStrFail[]; extern const char UnityStrIgnore[]; extern const char UnityStrErrFloat[]; extern const char UnityStrErrDouble[]; extern const char UnityStrErr64[]; extern const char UnityStrErrShorthand[]; /*------------------------------------------------------- * Test Running Macros *-------------------------------------------------------*/ #ifndef UNITY_EXCLUDE_SETJMP_H #define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0) #define TEST_ABORT() longjmp(Unity.AbortFrame, 1) #else #define TEST_PROTECT() 1 #define TEST_ABORT() return #endif /* This tricky series of macros gives us an optional line argument to treat it as RUN_TEST(func, num=__LINE__) */ #ifndef RUN_TEST #ifdef __STDC_VERSION__ #if __STDC_VERSION__ >= 199901L #define UNITY_SUPPORT_VARIADIC_MACROS #endif #endif #ifdef UNITY_SUPPORT_VARIADIC_MACROS #define RUN_TEST(...) RUN_TEST_AT_LINE(__VA_ARGS__, __LINE__, throwaway) #define RUN_TEST_AT_LINE(func, line, ...) UnityDefaultTestRun(func, #func, line) #endif #endif /* If we can't do the tricky version, we'll just have to require them to always include the line number */ #ifndef RUN_TEST #ifdef CMOCK #define RUN_TEST(func, num) UnityDefaultTestRun(func, #func, num) #else #define RUN_TEST(func) UnityDefaultTestRun(func, #func, __LINE__) #endif #endif #define TEST_LINE_NUM (Unity.CurrentTestLineNumber) #define TEST_IS_IGNORED (Unity.CurrentTestIgnored) #define UNITY_NEW_TEST(a) \ Unity.CurrentTestName = (a); \ Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)(__LINE__); \ Unity.NumberOfTests++; #ifndef UNITY_BEGIN #define UNITY_BEGIN() UnityBegin(__FILE__) #endif #ifndef UNITY_END #define UNITY_END() UnityEnd() #endif #ifndef UNITY_SHORTHAND_AS_INT #ifndef UNITY_SHORTHAND_AS_MEM #ifndef UNITY_SHORTHAND_AS_NONE #ifndef UNITY_SHORTHAND_AS_RAW #define UNITY_SHORTHAND_AS_OLD #endif #endif #endif #endif /*----------------------------------------------- * Command Line Argument Support *-----------------------------------------------*/ #ifdef UNITY_USE_COMMAND_LINE_ARGS int UnityParseOptions(int argc, char** argv); int UnityTestMatches(void); #endif /*------------------------------------------------------- * Basic Fail and Ignore *-------------------------------------------------------*/ #define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)(line)) #define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)(line)) /*------------------------------------------------------- * Test Asserts *-------------------------------------------------------*/ #define UNITY_TEST_ASSERT(condition, line, message) do {if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), (message));}} while(0) #define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)(line), (message)) #define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)(line), (message)) #define UNITY_TEST_ASSERT_EMPTY(pointer, line, message) UNITY_TEST_ASSERT(((pointer[0]) == 0), (UNITY_LINE_TYPE)(line), (message)) #define UNITY_TEST_ASSERT_NOT_EMPTY(pointer, line, message) UNITY_TEST_ASSERT(((pointer[0]) != 0), (UNITY_LINE_TYPE)(line), (message)) #define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT8 )(expected), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) #define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT16)(expected), (UNITY_INT)(UNITY_INT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) #define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT32)(expected), (UNITY_INT)(UNITY_INT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) #define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_UINT8 )(expected), (UNITY_INT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) #define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_UINT16)(expected), (UNITY_INT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) #define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_UINT32)(expected), (UNITY_INT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) #define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT8 )(expected), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT16)(expected), (UNITY_INT)(UNITY_INT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT32)(expected), (UNITY_INT)(UNITY_INT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_EQUAL_CHAR(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT8 )(expected), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR) #define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((UNITY_INT)(mask), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line)) #define UNITY_TEST_ASSERT_NOT_EQUAL_INT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_NOT_EQUAL_INT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) #define UNITY_TEST_ASSERT_NOT_EQUAL_INT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT16)(threshold), (UNITY_INT)(UNITY_INT16)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) #define UNITY_TEST_ASSERT_NOT_EQUAL_INT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT32)(threshold), (UNITY_INT)(UNITY_INT32)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) #define UNITY_TEST_ASSERT_NOT_EQUAL_UINT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_NOT_EQUAL_UINT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) #define UNITY_TEST_ASSERT_NOT_EQUAL_UINT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) #define UNITY_TEST_ASSERT_NOT_EQUAL_UINT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) #define UNITY_TEST_ASSERT_NOT_EQUAL_HEX8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_NOT_EQUAL_HEX16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_NOT_EQUAL_HEX32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_NOT_EQUAL_CHAR(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR) #define UNITY_TEST_ASSERT_GREATER_THAN_INT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_GREATER_THAN_INT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) #define UNITY_TEST_ASSERT_GREATER_THAN_INT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT16)(threshold), (UNITY_INT)(UNITY_INT16)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) #define UNITY_TEST_ASSERT_GREATER_THAN_INT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT32)(threshold), (UNITY_INT)(UNITY_INT32)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) #define UNITY_TEST_ASSERT_GREATER_THAN_UINT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_GREATER_THAN_UINT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) #define UNITY_TEST_ASSERT_GREATER_THAN_UINT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) #define UNITY_TEST_ASSERT_GREATER_THAN_UINT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) #define UNITY_TEST_ASSERT_GREATER_THAN_HEX8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_GREATER_THAN_HEX16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_GREATER_THAN_HEX32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_GREATER_THAN_CHAR(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR) #define UNITY_TEST_ASSERT_SMALLER_THAN_INT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_SMALLER_THAN_INT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) #define UNITY_TEST_ASSERT_SMALLER_THAN_INT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT16)(threshold), (UNITY_INT)(UNITY_INT16)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) #define UNITY_TEST_ASSERT_SMALLER_THAN_INT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT32)(threshold), (UNITY_INT)(UNITY_INT32)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) #define UNITY_TEST_ASSERT_SMALLER_THAN_UINT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_SMALLER_THAN_UINT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) #define UNITY_TEST_ASSERT_SMALLER_THAN_UINT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) #define UNITY_TEST_ASSERT_SMALLER_THAN_UINT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) #define UNITY_TEST_ASSERT_SMALLER_THAN_HEX8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_SMALLER_THAN_HEX16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_SMALLER_THAN_HEX32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_SMALLER_THAN_CHAR(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT) (threshold), (UNITY_INT) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 ) (threshold), (UNITY_INT)(UNITY_INT8 ) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT16) (threshold), (UNITY_INT)(UNITY_INT16) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT32) (threshold), (UNITY_INT)(UNITY_INT32) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT) (threshold), (UNITY_INT) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_CHAR(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 ) (threshold), (UNITY_INT)(UNITY_INT8 ) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT) (threshold), (UNITY_INT) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 ) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT16)(threshold), (UNITY_INT)(UNITY_INT16) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT32)(threshold), (UNITY_INT)(UNITY_INT32) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT) (threshold), (UNITY_INT) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_CHAR(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 ) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR) #define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin( (delta), (UNITY_INT) (expected), (UNITY_INT) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_INT8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT8 )(delta), (UNITY_INT)(UNITY_INT8 ) (expected), (UNITY_INT)(UNITY_INT8 ) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) #define UNITY_TEST_ASSERT_INT16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT16)(delta), (UNITY_INT)(UNITY_INT16) (expected), (UNITY_INT)(UNITY_INT16) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) #define UNITY_TEST_ASSERT_INT32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT32)(delta), (UNITY_INT)(UNITY_INT32) (expected), (UNITY_INT)(UNITY_INT32) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) #define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin( (delta), (UNITY_INT) (expected), (UNITY_INT) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) #define UNITY_TEST_ASSERT_UINT8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT8 )(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT8 )(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) #define UNITY_TEST_ASSERT_UINT16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT16)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) #define UNITY_TEST_ASSERT_UINT32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT32)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) #define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT8 )(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT8 )(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) #define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT16)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) #define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT32)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) #define UNITY_TEST_ASSERT_CHAR_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT8 )(delta), (UNITY_INT)(UNITY_INT8 ) (expected), (UNITY_INT)(UNITY_INT8 ) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR) #define UNITY_TEST_ASSERT_INT_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin( (delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT8 )(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin( (delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin( (UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT8 )(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_CHAR_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT8 )(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((UNITY_PTR_TO_INT)(expected), (UNITY_PTR_TO_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER) #define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)(line)) #define UNITY_TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len, line, message) UnityAssertEqualStringLen((const char*)(expected), (const char*)(actual), (UNITY_UINT32)(len), (message), (UNITY_LINE_TYPE)(line)) #define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), 1, (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((UNITY_INTERNAL_PTR)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_CHAR_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EACH_EQUAL_INT(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) (expected), (UNITY_INT_WIDTH / 8)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_INT8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_INT16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT16 )(expected), 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT32 )(expected), 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_UINT(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) (expected), (UNITY_INT_WIDTH / 8)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_UINT8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_UINT16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT16)(expected), 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_UINT32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT32)(expected), 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_HEX8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_HEX16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT16 )(expected), 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_HEX32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT32 )(expected), 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_PTR(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_PTR_TO_INT) (expected), (UNITY_POINTER_WIDTH / 8)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_STRING(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((UNITY_INTERNAL_PTR)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_CHAR(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR, UNITY_ARRAY_TO_VAL) #ifdef UNITY_SUPPORT_64 #define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) #define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_INT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_UINT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) #define UNITY_TEST_ASSERT_NOT_EQUAL_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_NOT_EQUAL_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_NOT_EQUAL_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_NOT_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) #define UNITY_TEST_ASSERT_GREATER_THAN_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_GREATER_THAN_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_GREATER_THAN_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) #define UNITY_TEST_ASSERT_SMALLER_THAN_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_SMALLER_THAN_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_SMALLER_THAN_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) #define UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT64)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT64)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT64)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_ARRAY) #else #define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_INT64_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_UINT64_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_GREATER_THAN_INT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_GREATER_THAN_UINT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_GREATER_THAN_HEX64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_SMALLER_THAN_INT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_SMALLER_THAN_UINT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_SMALLER_THAN_HEX64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #define UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) #endif #ifdef UNITY_EXCLUDE_FLOAT #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_EACH_EQUAL_FLOAT(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_FLOAT_IS_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #define UNITY_TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) #else #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((UNITY_FLOAT)(delta), (UNITY_FLOAT)(expected), (UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line)) #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((UNITY_FLOAT)(expected) * (UNITY_FLOAT)UNITY_FLOAT_PRECISION, (UNITY_FLOAT)(expected), (UNITY_FLOAT)(actual), (UNITY_LINE_TYPE)(line), (message)) #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((UNITY_FLOAT*)(expected), (UNITY_FLOAT*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EACH_EQUAL_FLOAT(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray(UnityFloatToPtr(expected), (UNITY_FLOAT*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_INF) #define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NEG_INF) #define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NAN) #define UNITY_TEST_ASSERT_FLOAT_IS_DETERMINATE(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_DET) #define UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_INF) #define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_NEG_INF) #define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_NAN) #define UNITY_TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_DET) #endif #ifdef UNITY_EXCLUDE_DOUBLE #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #else #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((UNITY_DOUBLE)(delta), (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line)) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((UNITY_DOUBLE)(expected) * (UNITY_DOUBLE)UNITY_DOUBLE_PRECISION, (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (UNITY_LINE_TYPE)(line), (message)) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((UNITY_DOUBLE*)(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray(UnityDoubleToPtr(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_INF) #define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NEG_INF) #define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NAN) #define UNITY_TEST_ASSERT_DOUBLE_IS_DETERMINATE(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_DET) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_INF) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_NEG_INF) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_NAN) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_DET) #endif /* End of UNITY_INTERNALS_H */ #endif