primitives.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * 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. * Author: g0tsu
  12. * Email: g0tsu at dnmx.0rg
  13. */
  14. #include <stdio.h>
  15. #include <assert.h>
  16. #include <libcaptcha.h>
  17. #include <global.h>
  18. #include <errno.h>
  19. static int load_incorrect_file() {
  20. char *fontfile = "nofile.found";
  21. lc_fontBuffer *font = lc_create_font(fontfile);
  22. if (font != NULL) {
  23. return 1;
  24. }
  25. lc_free(font);
  26. return 0;
  27. }
  28. static int load_font_test() {
  29. char *fontfile = "../ttf/cmunrm/cmunrm.ttf";
  30. lc_fontBuffer *font = lc_create_font(fontfile);
  31. if (!font) {
  32. perror("lc_create_font()");
  33. return 1;
  34. }
  35. lc_free(font);
  36. return 0;
  37. }
  38. static int create_bmp_glyph() {
  39. char *fontfile = "../ttf/cmunrm/cmunrm.ttf";
  40. lc_fontBuffer *font = lc_create_font(fontfile);
  41. lc_bmpGlyph *glyph;
  42. if (!font) {
  43. perror("lc_create_font()");
  44. return 1;
  45. }
  46. glyph = lc_create_glyph(font, 'g', 22);
  47. if (!glyph) {
  48. puts("lc_create_glyph()");
  49. return 1;
  50. }
  51. printf("glyph g is %dx%d\n", glyph->w, glyph->h);
  52. /* stbi_write_png("/tmp/glyph.png", glyph->w, glyph->h, 1, glyph->buffer, glyph->w);*/
  53. lc_free(glyph);
  54. lc_free(font);
  55. return 0;
  56. }
  57. static int random_stuff() {
  58. char bytes[4];
  59. lc_random_bytes(&bytes, 4);
  60. for (int i = 0; i < 4; i++) {
  61. printf("%x ", bytes[i] % 20);
  62. }
  63. return 0;
  64. }
  65. int main() {
  66. assert((2 + 2) == 4);
  67. assert(!load_incorrect_file());
  68. assert(!load_font_test());
  69. assert(!create_bmp_glyph());
  70. assert(!random_stuff());
  71. return 0;
  72. }