TestLogger.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "TestLogger.h"
  2. TestLogger::TestLogger()
  3. {
  4. }
  5. void TestLogger::print(const string* message, exception* ex, const string* function, const string* scriptname, const Script* sc, int line)
  6. {
  7. if(ex == nullptr)
  8. {
  9. if(message != nullptr)
  10. {
  11. output.push_back(*message);
  12. }
  13. }
  14. else
  15. {
  16. output.push_back(ex->what());
  17. }
  18. }
  19. void TestLogger::reset()
  20. {
  21. output.clear();
  22. }
  23. bool TestLogger::check(const string& name, fstream& check)
  24. {
  25. vector<string> file;
  26. while(!check.eof())
  27. {
  28. char buffer[256];
  29. check.getline(buffer, 256);
  30. if(buffer[0] != '\0')
  31. {
  32. file.push_back(buffer);
  33. }
  34. }
  35. if(file.size() != output.size())
  36. {
  37. printNoMatch(name, file);
  38. return false;
  39. }
  40. for(unsigned int i = 0; i < file.size(); i++)
  41. {
  42. if(file[i] != output[i])
  43. {
  44. printNoMatch(name, file);
  45. return false;
  46. }
  47. }
  48. return true;
  49. }
  50. void TestLogger::printNoMatch(const string& name, vector<string>& file)
  51. {
  52. cout << "error checking " << name << endl;
  53. cout << "Expected ---------------------------------------------" << endl;
  54. for(unsigned int i = 0; i < file.size(); i++)
  55. {
  56. cout << file[i] << endl;
  57. }
  58. cout << "Actual -----------------------------------------------" << endl;
  59. for(unsigned int i = 0; i < output.size(); i++)
  60. {
  61. cout << output[i] << endl;
  62. }
  63. cout << "------------------------------------------------------" << endl;
  64. }