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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.\nDIRECTIVE2:[sometext]\n\n";
  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. // Incomplete directive.
  24. ntr::fast_string buf7 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive:[ssometext\n# One more comment.";
  25. // Incomplete directive.
  26. ntr::fast_string buf8 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive:ssometext]\n# One more comment.";
  27. // Incomplete directive.
  28. ntr::fast_string buf9 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive [ssometext]\n# One more comment.";
  29. // Must have a space
  30. ntr::fast_string buf10 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive:[ ]\n# One more comment.";
  31. CFGFileParser test1(buf1);
  32. CFGFileParser test2(buf2);
  33. CFGFileParser test3(buf3);
  34. CFGFileParser test4(buf4);
  35. CFGFileParser test5(buf5);
  36. CFGFileParser test6(buf6);
  37. CFGFileParser test7(buf7);
  38. CFGFileParser test8(buf8);
  39. CFGFileParser test9(buf9);
  40. CFGFileParser test10(buf10);
  41. puts("CFG Parser Test for /ntr/\n<despair@netrunner.cc>\n");
  42. if (test1.ParseText()){
  43. puts("Test 1 passed. This is the reference string.\n");
  44. }
  45. else{
  46. puts("Test 1 FAILED!\n");
  47. }
  48. if (test2.ParseText()){
  49. puts("Test 2 passed.\n");
  50. }
  51. else{
  52. puts("Test 2 FAILED: Directives must not begin with a number.\n");
  53. }
  54. if (test3.ParseText()){
  55. puts("Test 3 passed. Mixed-case directives are valid.\n");
  56. }
  57. else{
  58. puts("Test 3 FAILED: see above\n");
  59. }
  60. if (test4.ParseText()){
  61. puts("Test 4 passed.\n");
  62. }
  63. else{
  64. puts("Test 4 FAILED: A stray comment.\n");
  65. }
  66. if (test5.ParseText()){
  67. puts("Test 5 passed.");
  68. }
  69. else{
  70. puts("Test 5 FAILED: Old-style Lynx CFG directive. No longer valid here.\n");
  71. }
  72. if (test6.ParseText()){
  73. puts("Test 6 passed.");
  74. }
  75. else{
  76. puts("Test 6 FAILED: Leading non-alpha symbol\n");
  77. }
  78. if (test7.ParseText()){
  79. puts("Test 7 passed.");
  80. }
  81. else{
  82. puts("Test 7 FAILED: Missing terminator\n");
  83. }
  84. if (test8.ParseText()){
  85. puts("Test 8 passed.");
  86. }
  87. else{
  88. puts("Test 8 FAILED: Missing separator\n");
  89. }
  90. if (test9.ParseText()){
  91. puts("Test 9 passed.");
  92. }
  93. else{
  94. puts("Test 9 FAILED: Missing colon separator\n");
  95. }
  96. if (test10.ParseText()){
  97. puts("Test 10 passed. Blank directives MUST have at least one space");
  98. }
  99. else{
  100. puts("Test 10 FAILED: Null directive\n");
  101. }
  102. return 0;
  103. }