PageRenderTime 34ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/tests/asprintf.c

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C | 42 lines | 18 code | 6 blank | 18 comment | 4 complexity | 0503cfeca72ef70fe345b0fd44dae75c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /*
  2. asprintf.c - test `asprintf' function
  3. Copyright (C) 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. int main(void) {
  21. int result;
  22. char * s;
  23. result = asprintf(&s, "%s %d %c", "abc", 123, 'x');
  24. assert(result == 9);
  25. assert(strcmp("abc 123 x", s) == 0);
  26. free(s);
  27. char * long_string = "abcdefghijklmnopqrstuvwxyz";
  28. result = asprintf(&s, "%s %s %s %s", long_string, long_string, long_string, long_string);
  29. assert(result == 107);
  30. assert(strcmp("abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz", s) == 0);
  31. free(s);
  32. exit(EXIT_SUCCESS);
  33. }