LabelSplicer_test.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <https://www.gnu.org/licenses/>.
  14. */
  15. #include "switch/LabelSplicer.h"
  16. #include "util/Assert.h"
  17. #include <stdio.h>
  18. #include <inttypes.h>
  19. static void unsplice()
  20. {
  21. Assert_true(0x13 == LabelSplicer_unsplice(0x13, 1));
  22. }
  23. static void splice()
  24. {
  25. uint64_t goHere = 0x04; // 000000100
  26. uint64_t viaHere = 0x04; // 000000100
  27. uint64_t expected = 0x10; // 000010000
  28. uint64_t out = LabelSplicer_splice(goHere, viaHere);
  29. printf("Splicing %" PRIu64 " with %" PRIu64 " yields %" PRIu64 ", expecting %" PRIu64 "\n",
  30. goHere, viaHere, out, expected);
  31. Assert_true(expected == out);
  32. }
  33. static void routesThrough()
  34. {
  35. // 0000000000000000100100000000101011101010100101011100101001010101
  36. uint64_t dst = 0x0000900aea95ca55;
  37. // 0000000000000000000000010110010100100110001110011100011001010101
  38. uint64_t mid = 0x000001652639c655;
  39. Assert_true(!LabelSplicer_routesThrough(dst, mid));
  40. Assert_true(LabelSplicer_routesThrough(dst, 1));
  41. }
  42. int main()
  43. {
  44. splice();
  45. routesThrough();
  46. unsplice();
  47. return 0;
  48. }