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.

TestCFG.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "netrunner.h"
  2. #include "CFGFileParser.h"
  3. #ifdef _WIN32
  4. extern "C"{void init_heap();}
  5. #endif
  6. int main(void){
  7. #ifdef _WIN32
  8. init_heap();
  9. #endif
  10. // test vectors
  11. // This is our reference, should always be valid.
  12. ntr::fast_string buf1 = "# This is a comment.\n.This is a formatting directive.\n# The following is a valid directive:\nHOMEPAGE:[http://motherfuckingwebsite.com]\n# Another comment.";
  13. // Leading number.
  14. ntr::fast_string buf2 = "# This is a comment.\n.This is a formatting directive.\n# Not a valid directive:\n4chan:[sometext here]\n# Still another comment.";
  15. // Lowercase letters. Also a valid directive.
  16. ntr::fast_string buf3 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive:[ssometext]\n# One more comment.";
  17. // Unescaped comment.
  18. ntr::fast_string buf4 = "# A comment.\nUnescaped comment!\n# A valid comment.\n\n# The following directive is untouched, since the parser SHOULD have quit earlier:\nBUGURL:[http://rvx86.net]\n# One final comment.";
  19. // Old-style Lynx directive. Invalid here.
  20. ntr::fast_string buf5 = "# This is a comment.\n.This is a formatting directive.\n# The following is a valid directive in Lynx, but not for NetRunner:\nHOMEPAGE:http://motherfuckingwebsite.com\n# Another comment.";
  21. // Invalid leading character.
  22. ntr::fast_string buf6 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\n^bad_directive:[ssometext]\n# One more comment.";
  23. // The casts LOOK useless, but they're not.
  24. CFGFileParser test1(buf1);
  25. CFGFileParser test2(buf2);
  26. CFGFileParser test3(buf3);
  27. CFGFileParser test4(buf4);
  28. CFGFileParser test5(buf5);
  29. CFGFileParser test6(buf6);
  30. puts("CFG Parser Test for /ntr/\n<despair@netrunner.cc>\n");
  31. if (test1.ParseText()){
  32. puts("Test 1 passed. This is the reference string.\n");
  33. }
  34. else{
  35. puts("Test 1 FAILED!\n");
  36. }
  37. if (test2.ParseText()){
  38. puts("Test 2 passed.\n");
  39. }
  40. else{
  41. puts("Test 2 FAILED: see above\nDirectives must not begin with a number.\n");
  42. }
  43. if (test3.ParseText()){
  44. puts("Test 3 passed. Mixed-case directives are valid.\n");
  45. }
  46. else{
  47. puts("Test 3 FAILED: see above\n");
  48. }
  49. if (test4.ParseText()){
  50. puts("Test 4 passed.\n");
  51. }
  52. else{
  53. puts("Test 4 FAILED: see above\nA stray comment.\n");
  54. }
  55. if (test5.ParseText()){
  56. puts("Test 5 passed.");
  57. }
  58. else{
  59. puts("Test 5 FAILED: see above\nOld-style Lynx CFG directive. No longer valid here.\n");
  60. }
  61. if (test6.ParseText()){
  62. puts("Test 6 passed.");
  63. }
  64. else{
  65. puts("Test 6 FAILED: see above\nLeading non-alpha symbol\n");
  66. }
  67. return 0;
  68. }