Identity_test.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "util/Identity.h"
  16. #include "util/Assert.h"
  17. struct Thing
  18. {
  19. int counter;
  20. Identity
  21. };
  22. static struct Thing* increment(struct Thing* t)
  23. {
  24. t->counter++;
  25. return t;
  26. }
  27. int main()
  28. {
  29. struct Thing t = {
  30. .counter = 0
  31. };
  32. struct Thing* tp = &t;
  33. Identity_set(tp);
  34. tp = Identity_check(increment(tp));
  35. Assert_true(tp == &t);
  36. Assert_true(t.counter == 1);
  37. return 0;
  38. }