PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/tests/recursive-dir-list.c

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C | 93 lines | 59 code | 13 blank | 21 comment | 9 complexity | 03528a6c69839a4c5c788fbbcb7afea1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /*
  2. recursive-dir-list.c - test `make_recursive_dir_list' function
  3. Copyright (C) 2007, 2008 siliconforks.com
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include <assert.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "util.h"
  20. struct Expected {
  21. int count;
  22. const char * name;
  23. };
  24. void cleanup(void) {
  25. system("rm -fr DIR");
  26. }
  27. void touch(const char * file) {
  28. FILE * f = fopen(file, "w");
  29. if (f == NULL) {
  30. fatal("cannot open file: %s", file);
  31. }
  32. fclose(f);
  33. }
  34. void verify(struct Expected * expected, struct DirListEntry * actual, int length) {
  35. struct DirListEntry * p = actual;
  36. while (p != NULL) {
  37. char * name = p->name;
  38. for (int i = 0; i < length; i++) {
  39. if (strcmp(expected[i].name, name) == 0) {
  40. expected[i].count++;
  41. break;
  42. }
  43. }
  44. p = p->next;
  45. }
  46. /* now verify the totals */
  47. for (int i = 0; i < length; i++) {
  48. assert(expected[i].count == 1);
  49. }
  50. }
  51. int main(void) {
  52. atexit(cleanup);
  53. system("rm -fr DIR");
  54. /* simple case */
  55. xmkdir("DIR");
  56. xmkdir("DIR/a");
  57. xmkdir("DIR/a/b");
  58. xmkdir("DIR/c");
  59. xmkdir("DIR/d");
  60. touch("DIR/0");
  61. touch("DIR/a/1");
  62. touch("DIR/a/b/2");
  63. touch("DIR/c/3");
  64. touch("DIR/c/4");
  65. /* DIR/d is empty */
  66. struct Expected expected[] = {
  67. {0, "c/4"},
  68. {0, "c/3"},
  69. {0, "a/b/2"},
  70. {0, "a/1"},
  71. {0, "0"},
  72. };
  73. struct DirListEntry * list = make_recursive_dir_list("DIR");
  74. verify(expected, list, sizeof(expected) / sizeof(expected[0]));
  75. free_dir_list(list);
  76. exit(EXIT_SUCCESS);
  77. }