testchomp.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
  3. * All rights reserved.
  4. * This component and the accompanying materials are made available
  5. * under the terms of the License "Eclipse Public License v1.0"
  6. * which accompanies this distribution, and is available
  7. * at the URL "http://www.eclipse.org/legal/epl-v10.html".
  8. *
  9. * Initial Contributors:
  10. * Nokia Corporation - initial contribution.
  11. *
  12. * Contributors:
  13. *
  14. * Description:
  15. * This programs tests the chompCommand function used by talon.
  16. */
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. #include <stdio.h>
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #include <fcntl.h>
  23. #include "chomp.h"
  24. #include "log.h"
  25. char *positives[] = {
  26. "c:\\apps\\talon.exe -c \"armcc -o barney.o\"",
  27. "c:\\apps\\sbs2112-capabilites\\bin\\talon.exe -c \"armcc -o barney.o\"",
  28. "\"c:\\apps and stuff\\talon.exe\" -c \"armcc -o barney.o\"",
  29. "\"c:\\apps-can-cause-crxxx\\talon.exe\" -c \"armcc -o barney.o\"",
  30. "c:\\bigspaces-\" \"\\talon.exe -c \"armcc -o barney.o\"",
  31. "c:\\bigspaces2\" \"\\talon.exe -c \"armcc -o barney.o\"",
  32. "c:\\apps\\talon.exe -c \"armcc -o barney.o\"",
  33. "c:\\\"apps\"\\talon.exe -c \"armcc -o barney.o\"",
  34. "c:\\\"ap ps\"\\talon.exe -c \"armcc -o barney.o\"",
  35. (char *)0
  36. };
  37. char *negatives[] = {
  38. "c:\\apps\\talon.exe -c\"armcc -o barney.o\"",
  39. "c:\\apps and stuff\\talon.exe -c \"armcc -o barney.o\"",
  40. "c:\\apps\\talon.exe -c armcc -o barney.o",
  41. "c:\\apps\\talon.exe commandlist.tmp",
  42. (char *)0
  43. };
  44. char commandstr[]="armcc -o barney.o\"";
  45. int main(int argc, char *argv[])
  46. {
  47. int i;
  48. int errors = 0;
  49. /* loglevel = LOGDEBUG; /* useful to leave this here */
  50. for (i=0; positives[i] != (char *)0 ; i++)
  51. {
  52. char * c = chompCommand(positives[i]);
  53. if (!c)
  54. {
  55. fprintf(stdout,"error: test failed with NULL on: %s\n", positives[i]);
  56. errors++;
  57. continue;
  58. }
  59. if (strcmp(commandstr, c) != 0)
  60. {
  61. fprintf(stdout,"error: test failed with %s on: %s\n", c,positives[i]);
  62. errors++;
  63. continue;
  64. }
  65. fprintf(stdout,"ok: %s\n", positives[i]);
  66. }
  67. for (i=0; negatives[i] != (char *)0 ; i++)
  68. {
  69. char * c = chompCommand(negatives[i]);
  70. if (c)
  71. {
  72. fprintf(stdout,"error: negatice test failed with %s on: %s\n", c, negatives[i]);
  73. errors++;
  74. continue;
  75. }
  76. fprintf(stdout,"ok: negative: %s\n", negatives[i]);
  77. }
  78. fprintf(stdout,"TOTAL errors: %d\n", errors);
  79. return errors;
  80. }