///////////////////////////////////////////////////////////////////////////// // unitTest_Scanner.cpp - scanner Unit Tests // // ver 1.0 Uses testHarness module // // // // Language: Visual C++, ver 7.0 // // Platform: Dell Dimension 8300, Windows XP Prof, SP 1 // // Application: CSE687 prototype for project #1, Spring 2004 // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////////////// /* * Module Operations: * ================== * Provides a set of unit tests to validate Scanner module, using the * TestHarness module. * * Maintenance History: * ==================== * ver 1.0 : 24 Feb 04 * - first release * * Build Process: * ============== * Required Files: * Scanner.h, Scanner.cpp, Grammar.h, Grammar.cpp, Display.h, Display.cpp, * CppSemiExp.h, CppSemiExp.cpp, CppToker.h, CppToker.cpp, * TestHarness.h, TestHarness.cpp, UnitTest_Scanner.cpp * * Compiler Command: * cl /DUNITTEST_SCANNER /EHsc \ * Scanner.cpp, Grammar.cpp, Display.cpp CppSemiExp.cpp CppToker.cpp \ * TestHarness.cpp UnitTest_Scanner.cpp */ // #ifdef UNITTEST_SCANNER #include #include #include #include "scanner.h" #include "grammar.h" #include "display.h" #include "testharness.h" using namespace Scanner; using namespace CodeAnal; using namespace TestHarness; /* /////////////////////////////////////////////////////////////////////// // test showToString() // class showToString : public test { public: showToString(output& out) : test(out) {} bool operator()() { title("showToString() function"); std::istringstream one("one\ntwo\nthree;"); CToker toker(&one); CSemiExp semi(&toker); while(semi.get()) tout << semi.showToString("",true); semi.get(); tout << semi.showToString("",true) << std::endl; return true; } }; */ // /////////////////////////////////////////////////////////////////////// // test CppSemiExp assignment // class CrashWhenSetWorkingDirectoryInProperties : public test { public: CrashWhenSetWorkingDirectoryInProperties(output& out) : test(out) {} void passArgs(int argc, char* argv[]) { _argc = argc; _argv = argv; } bool operator()() { title("Crash when setting working directory in properties"); tout.write(); scanner s; defaultProc dp(s); s.Register(&dp); for(int i=1; i<_argc; ++i) { if(s.isCommand(_argv[i])) s.processCommand(_argv[i]); else s.scan(_argv[i]); } tout << "\n\n"; return true; // if we get here we didn't crash } private: int _argc; char **_argv; }; int main(int argc, char* argv[]) { stdOutput out; tester t(out, "Testing scanner Class"); nullOutput null; // null.showAll(true); CrashWhenSetWorkingDirectoryInProperties crash(out); crash.passArgs(argc, argv); t.registerTest(&crash); t.execute(out); std::cout << "\n\n"; } #endif