des bubulles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tbb.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * this is rudimentary test for the bubulles manager
  3. *
  4. * contact: <tth> on IRC freenode#tetalab
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include "bubulles.h"
  9. /* --------------------------------------------------------------------- */
  10. void test_alloc_free(int nbelm)
  11. {
  12. BBList *bublist;
  13. int foo;
  14. bublist = alloc_bubulles("plop !", nbelm, 0);
  15. if (NULL==bublist) {
  16. fprintf(stderr, "err in %s, aborting...\n", __func__);
  17. abort();
  18. }
  19. print_bublist_desc(bublist, 1);
  20. foo = free_bubulles(bublist, 0);
  21. fprintf(stderr, "free bubulles -> %d\n", foo);
  22. }
  23. /* --------------------------------------------------------------------- */
  24. int test_push_pop(int nbelm)
  25. {
  26. BBList *bublist;
  27. int foo, idx;
  28. Bubulle bubulle;
  29. bublist = alloc_bubulles("push & pop", nbelm, 0);
  30. for (idx=0; idx<nbelm; idx++) {
  31. bubulle.p.x = (double)idx;
  32. if (idx & 0xf0)
  33. bubulle.p.y = bubulle.p.z = 0.3;
  34. else
  35. bubulle.p.y = bubulle.p.z = 0.8;
  36. foo = push_bubulle(bublist, &bubulle);
  37. }
  38. /* WTF ? where is the 'pop' test ? */
  39. foo = bubulles_to_data("dummy-file", NULL, bublist, 0);
  40. fprintf(stderr, "ecriture bubulles -> %d\n", foo);
  41. foo = free_bubulles(bublist, 0);
  42. fprintf(stderr, "free bubulles -> %d\n", foo);
  43. return 0;
  44. }
  45. /* --------------------------------------------------------------------- */
  46. int test_cleanfill_my_bublist(int krkrkr)
  47. {
  48. BBList *bublist;
  49. int foo;
  50. bublist = alloc_bubulles("cleanfill", 567890, 0);
  51. foo = cleanfill_my_bublist(bublist, 0);
  52. fprintf(stderr, "clean & fill -> %d\n", foo);
  53. free_bubulles(bublist, 0);
  54. return 0;
  55. }
  56. /* --------------------------------------------------------------------- */
  57. int test_peek_poke(int nbre)
  58. {
  59. BBList *bublist;
  60. int foo, in, out;
  61. Bubulle bubulle;
  62. bublist = alloc_bubulles("peek & poke", nbre, 0);
  63. print_bublist_desc(bublist, 0);
  64. in = nbre / 2;
  65. out = nbre + 42;
  66. foo = peek_bubulle(bublist, &bubulle, in);
  67. fprintf(stderr, "peek 1 -> %7d\n", foo);
  68. foo = niceprint_bubulle(&bubulle, 0);
  69. if (foo) fprintf(stderr, "niceprint -> %d\n", foo);
  70. foo = peek_bubulle(bublist, &bubulle, out);
  71. fprintf(stderr, "peek 2 -> %7d\n", foo);
  72. bubulle.p.y = 3.14159;
  73. foo = poke_bubulle(bublist, &bubulle, in);
  74. fprintf(stderr, "poke 2 -> %7d\n", foo);
  75. foo = peek_bubulle(bublist, &bubulle, in);
  76. fprintf(stderr, "peek 3 -> %7d\n", foo);
  77. foo = niceprint_bubulle(&bubulle, 0);
  78. if (foo) fprintf(stderr, "niceprint -> %d\n", foo);
  79. free_bubulles(bublist, 0);
  80. return 0;
  81. }
  82. /* --------------------------------------------------------------------- */
  83. int main(int argc, char *argv[])
  84. {
  85. int foo;
  86. printf("*** Bubulles Testing -- %s %s\n\n", __DATE__, __TIME__);
  87. bubulles_version(1);
  88. test_alloc_free(5);
  89. test_push_pop(20000);
  90. test_cleanfill_my_bublist(999);
  91. foo = test_peek_poke(5000);
  92. fprintf(stderr, "test peek/poke -> %d\n", foo);
  93. return 0;
  94. }