utRemoveComments.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "utRemoveComments.h"
  2. CPPUNIT_TEST_SUITE_REGISTRATION (RemoveCommentsTest);
  3. void RemoveCommentsTest :: setUp (void)
  4. {
  5. // nothing to do here
  6. }
  7. void RemoveCommentsTest :: tearDown (void)
  8. {
  9. // nothing to do here
  10. }
  11. void RemoveCommentsTest :: testSingleLineComments (void)
  12. {
  13. const char* szTest = "int i = 0; \n"
  14. "if (4 == //)\n"
  15. "\ttrue) { // do something here \n"
  16. "\t// hello ... and bye //\n";
  17. char* szTest2 = new char[::strlen(szTest)+1];
  18. ::strcpy(szTest2,szTest);
  19. const char* szTestResult = "int i = 0; \n"
  20. "if (4 == \n"
  21. "\ttrue) { \n"
  22. "\t \n";
  23. CommentRemover::RemoveLineComments("//",szTest2,' ');
  24. CPPUNIT_ASSERT(0 == ::strcmp(szTest2,szTestResult));
  25. delete[] szTest2;
  26. }
  27. void RemoveCommentsTest :: testMultiLineComments (void)
  28. {
  29. char* szTest =
  30. "/* comment to be removed */\n"
  31. "valid text /* \n "
  32. " comment across multiple lines */"
  33. " / * Incomplete comment */ /* /* multiple comments */ */";
  34. const char* szTestResult =
  35. " \n"
  36. "valid text "
  37. " "
  38. " / * Incomplete comment */ */";
  39. char* szTest2 = new char[::strlen(szTest)+1];
  40. ::strcpy(szTest2,szTest);
  41. CommentRemover::RemoveMultiLineComments("/*","*/",szTest2,' ');
  42. CPPUNIT_ASSERT(0 == ::strcmp(szTest2,szTestResult));
  43. delete[] szTest2;
  44. }